This blog is a quick 101 introduction for anybody wanting to know how to quickly and easily deploy an Azure resource using Terraform with end to end easy instructions.
Deployment Steps:
Step 1 - Authenticating on Azure
Terraform must authenticate to Azure to create infrastructure
az login
Your browser will open and prompt you to enter your Azure login credentials. After a successful authentication, your terminal will display your subscription information.
Step 2 - select your target subscription
Find the subscription id for your target subscription then set the subscription.
az account set –subscription “dc5a212d-0000-0000-0000-0000”
Step 3 - Create a Service Principal
Provisioning an Azure AD Service Principal will be automated by Terraform.
The Service Principal will be used by Terraform to perform actions on your behalf.
Begin by assigning the permission and scope of the Service Principal
(Here we are assigning Contributor role to the subscription).
The Service Principal will be provisioned by TF.
az ad sp create-for-rbac –role=”Contributor” –scopes=”/subscriptions/dc5a212d-0000-0000-0000-0000″
Step 4 - Set your environment variables from the Service Principal
Once you have executed the command from step 3, you will be presented with the new service principal created by and for Terraform.
HashiCorp recommends setting these values as environment variables rather than saving them in your Terraform configuration.
$ $Env:ARM_CLIENT_ID = "<APPID_VALUE>"
$ $Env:ARM_CLIENT_SECRET = "<PASSWORD_VALUE>"
$ $Env:ARM_SUBSCRIPTION_ID = "<SUBSCRIPTION_ID>"
$ $Env:ARM_TENANT_ID = "<TENANT_VALUE>"
Deployments
Write configuration
Step 1 – Create a local folder
New-Item -Path “c:\” -Name “allen-terraform-azure” -ItemType “directory”
Step 2 – Create a new file called main.tf
New-Item C:\allen-terraform-azure\main.tf
Code can be found here for populating with various resources.
Step 3 – Change to TF directory
Cd C:\allen-terraform-azure\
Step 4 – Initialize your Terraform configuration
terraform init
Step 5 – Format and validate the configuration
terraform fmt
If there are no errors in your format, then you won’t see any output.
Step 6 – Apply your Terraform Configuration
terraform apply
You will be asked for confirmation > yes
Step 7 – Inspect the current state
terraform show
Step 9 - Verification
Verify the build in your Azure Portal
–End–
Hi there just wanted to give you a quick heads up. The words in your content seem to be running off the screen in Internet explorer. I’m not sure if this is a formatting issue or something to do with browser compatibility but I figured I’d post to let you know. The design look great though! Hope you get the problem fixed soon. Thanks
F*ckin¦ tremendous things here. I¦m very glad to peer your post. Thanks so much and i am taking a look forward to touch you. Will you kindly drop me a mail?
As I website owner I believe the content material here is real good, thanks for your efforts.