Variety of lab scenarios using Terraform and Azure
There are two parts of the lab configuration which require additional security setup:
-
Using Terraform to make changes including adding and removing objects in a subscription
- In the labs below we use the service principal with a client secret configuration. We recommend setting these values using the
ARM_SUBSCRIPTION_ID, ARM_TENANT_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET
environment variables, but you can also login via Azure CLI (az login) as an alternative.
- In the labs below we use the service principal with a client secret configuration. We recommend setting these values using the
-
Using Azure to store Terraform state information for usage by other modules and scripts
- We use a SAS token to access the storage container for the below examples. We recommend setting this value using the
ARM_SAS_TOKEN
environment variable.
- We use a SAS token to access the storage container for the below examples. We recommend setting this value using the
- Install Visual Studio Code (download here)
- Install Git SCM (download here)
- Edit example.code-workspace
- Update the values for your Azure Security Configuration
- Save or rename file to your preference
- Clone github repo to a working directory on your local filesystem (must be run as an account with ability to create symlinks)
git -c core.symlinks=true clone https://github.com/chkp-wbelt/tf-labs.git
- Open new workspace file in Visual Studio Code
Each configuration step requires running the terraform init and apply process, the plan step is optional and purely for informational purposes. The directory from the project root is displayed in ()s
-
Run storage configuration (setup/storage)
- Open setup/storage/main.tf for editing in VS code.
- Update main.tf file with the
prefix
,location
andstorage_suffix
values appropriate for your environment. You may also optionally edit/update thetags
. The resulting storage account name will be prefix with storage_suffix added. In the example, prefix=lab, storage_suffix=storage813 resulting in a storage account name oflabstorage813
- Terminal -> New Terminal in VS code with the main.tf file still open for editing. This should open a new terminal in the setup/storage directory.
terraform init terraform plan terraform apply
-
Run environment configuration (setup/environment)
- Open setup/environment/main.tf for editing in VS code.
- Update main.tf file with the
value
appropriate for your environment. This is the terraform workspace that will be used for the next step (network setup). If this is a new environment, any value except "default" can be used, if this is an existing environment the name of the existing terraform workspace should be used. - Terminal -> New Terminal in VS code with the main.tf file still open for editing. This should open a new terminal in the setup/environment directory.
terraform init terraform plan terraform apply
-
Run network configuration (setup/network)
- Open setup/network/main.tf for editing in VS code.
- Update main.tf file with the
prefix
andlocation
appropriate for your environment. This should be the same values used in step 1 above in setup/storage. You may also optionally edit/update thetags
. - Terminal -> New Terminal in VS code with the main.tf file still open for editing. This should open a new terminal in the setup/network directory.
- Use a
vnet_address_space
value for your environment. The example of 10.50.200.0/22 is used below. This will create three /24 subnets from the range. 0 = external, 1 = dmz, 3 = internal.
terraform init terraform plan -var="vnet_address_space=10.50.200.0/22" terraform apply -var="vnet_address_space=10.50.200.0/22"