WEBVTT

00:00:00.540 --> 00:00:04.019
In this module, we're going to do a quick demo here,

00:00:04.030 --> 00:00:07.260
and it's something that you can use to show how Terrascan

00:00:07.260 --> 00:00:10.060
would operate in a real life scenario.

00:00:10.110 --> 00:00:11.150
So first,

00:00:11.150 --> 00:00:14.160
I'm going to open a pull request against a

00:00:14.160 --> 00:00:16.350
repository that I'm making a change to,

00:00:17.140 --> 00:00:20.160
and that pull request is going to run Terrascan,

00:00:20.840 --> 00:00:22.720
and then I'll merge the pull request,

00:00:22.730 --> 00:00:26.150
and we'll delegate the apply to Terraform Cloud.

00:00:26.740 --> 00:00:27.550
Let's get started.

00:00:29.040 --> 00:00:31.620
So I'm here in my GitHub repository,

00:00:31.890 --> 00:00:35.200
and there is a couple of things that we want to go through first.

00:00:35.740 --> 00:00:39.690
First, I've got main.tf, which is what we've been using this whole time.

00:00:39.770 --> 00:00:42.970
I've fixed all of the issues here just for the demo,

00:00:42.970 --> 00:00:47.090
so nothing should pop up on our Terrascan action.

00:00:47.290 --> 00:00:49.530
And then I have another branch here.

00:00:49.530 --> 00:00:52.380
If I go over to this other branch.

00:00:52.670 --> 00:00:54.850
As of the time of this recording,

00:00:54.940 --> 00:00:58.780
HashiCorp has updated their Terraform AWS provider,

00:00:58.940 --> 00:01:02.600
so if I go back here into main.tf, it looks a little bit different.

00:01:02.850 --> 00:01:05.620
This is going to be exactly the same bucket with the exactly

00:01:05.620 --> 00:01:08.230
the same configuration as the main branch,

00:01:08.240 --> 00:01:11.690
but because of the provider changes, this is how this code looks.

00:01:11.690 --> 00:01:12.790
It's a little bit different.

00:01:13.010 --> 00:01:15.510
It's broken out into multiple resources,

00:01:15.520 --> 00:01:17.860
instead of just attributes of one resource.

00:01:18.540 --> 00:01:23.210
So let's go back here to the master branch, and go into my GitHub workflow.

00:01:23.450 --> 00:01:26.010
I've got a single GitHub workflow here,

00:01:26.040 --> 00:01:29.610
and the first thing I'm going to do is run Terrascan,

00:01:29.620 --> 00:01:33.330
so that's between Lines 8 and 26.

00:01:33.500 --> 00:01:36.540
We did this a little bit in the last section,

00:01:36.700 --> 00:01:39.660
but this time, it's going to run to completion.

00:01:40.740 --> 00:01:42.260
And then if I scroll down a little bit,

00:01:42.260 --> 00:01:47.200
this is another Terraform action that will run a validate plan format,

00:01:47.200 --> 00:01:50.060
all of those other Terraform commands that we want when

00:01:50.060 --> 00:01:52.490
we're doing a Terraform workflow.

00:01:52.630 --> 00:01:54.230
And also to make this effective,

00:01:54.230 --> 00:01:58.560
I want to go up here to Settings, and then look at my Branches,

00:01:59.420 --> 00:02:02.760
and then go under Branch protection rules, and hit Edit here,

00:02:03.240 --> 00:02:06.010
and you'll see that I've got this Terraform action

00:02:06.010 --> 00:02:07.850
set as a branch protection rule.

00:02:07.850 --> 00:02:11.810
So what that means is that this GitHub action has to

00:02:11.810 --> 00:02:14.590
pass successfully if I want to merge.

00:02:14.930 --> 00:02:17.650
If I don't set this as a Branch protection rule or if I

00:02:17.650 --> 00:02:20.840
don't require that the status passes, even if there is a failure,

00:02:20.840 --> 00:02:22.460
I can still merge my branch.

00:02:22.810 --> 00:02:25.360
This isn't a requirement, but it is a best practice,

00:02:25.360 --> 00:02:26.850
so something to keep in mind.

00:02:27.600 --> 00:02:31.090
For now, let's go back to my Demo‑Repo here,

00:02:31.100 --> 00:02:33.450
and I'll open up a new pull request.

00:02:35.940 --> 00:02:37.920
And you see I've done this a few times already,

00:02:37.920 --> 00:02:41.060
but this will just go over the deltas and the changes.

00:02:41.190 --> 00:02:45.150
I'll go ahead and hit Create, and assign this to myself.

00:02:46.040 --> 00:02:47.670
When I open this pull request,

00:02:47.680 --> 00:02:51.440
it's going to kick off that Terraform action with

00:02:51.440 --> 00:02:54.130
Terrascan and the Terraform validate, init,

00:02:54.140 --> 00:02:54.800
and so on.

00:02:54.990 --> 00:02:56.420
So you've seen this run already.

00:02:56.430 --> 00:02:58.860
Let me go over to the Actions tab,

00:03:00.340 --> 00:03:03.170
and this will just give you an idea that this is running,

00:03:03.170 --> 00:03:07.020
this is going to make sure that all of my Terraform code is valid,

00:03:07.030 --> 00:03:10.080
all of it has passed its Terrascan checks,

00:03:10.170 --> 00:03:13.030
and like I said, I've already made sure that this is going to pass.

00:03:13.540 --> 00:03:18.760
So let's go back here to the pull request and wait for these checks to finish.

00:03:21.640 --> 00:03:23.310
Alright, that didn't take long at all.

00:03:23.310 --> 00:03:26.460
So you see GitHub actions has commented on this pull request,

00:03:27.040 --> 00:03:29.730
all of my checks have passed, including Terrascan.

00:03:30.260 --> 00:03:34.470
In this case, I'm actually delegating the plan to Terraform Cloud,

00:03:34.480 --> 00:03:38.800
so you'll see here that Terraform, I've got a Terraform Cloud workspace set up,

00:03:38.810 --> 00:03:44.380
and it's running the plan and apply process once this gets merged,

00:03:44.390 --> 00:03:48.730
but also important to note that my Terrascan action also passed successfully.

00:03:48.740 --> 00:03:53.220
So if I go here, Terrascan is right there, and it did pass.

00:03:53.570 --> 00:03:54.950
And then once I merge this,

00:03:54.960 --> 00:03:59.040
I've got another workflow for Terraform Cloud that will pick up the

00:03:59.040 --> 00:04:02.310
changes and then run this in a Terraform Cloud run.

00:04:02.330 --> 00:04:07.470
So that's how Terrascan can be used in a more realistic scenario.

00:04:07.470 --> 00:04:11.700
And with that, I'll go ahead and wrap up this course.

00:04:12.060 --> 00:04:14.960
Thank you all so much for watching, and I hope to see you all next time.
