Skip to content

hdubel94/TerraformBasics

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform basics

This repository contains an example on how to set up an Azure APIM CI/CD pipeline using Terraform. Blog Post

Running this example

  1. Install terraform https://learn.hashicorp.com/tutorials/terraform/install-cli

  2. Log in to Azure through the console: https://docs.microsoft.com/en-us/azure/developer/terraform/get-started-cloud-shell

az login
az account set --subscription={YourSubscriptionId} # If you need to select multiple accounts
  1. Initialize terraform
terraform init
  1. Change the apim_name under the main.tfvars to ensure you have a unique APIM name.

  2. Run a plan to check what is going to happen

terraform plan -var-file="main.tfvars"
  1. Try to apply:
terraform apply -var-file="main.tfvars"

If you were setting up terraform from scratch:

After the Terraform init:

  1. create main.tf with:
provider "azurerm" {    
    version = "=2.20.0"	    
    features {}  
}
  1. Creating a resource group*
resource "azurerm_resource_group" "example" {    
    name = "tf-test"
    location = "West Europe"    
}

terraform plan

terraform apply

Next steps:

It's important to understand about the terraform states. States are the current state of what terraform thinks your Azure infrastructure looks like, it knows what to delete/create/update from it. So for collaborating with multiple people, this file should be in some sort of backend, for example Azure Storage or AWS S3

This file also contains sensitive data, so it's recommended not to store in source control.

Store states in an azure storage

https://docs.microsoft.com/en-us/azure/developer/terraform/store-state-in-azure-storage

Parameretise / Multi environment

If you are going to have to do multiple environments, you can get guidance here:

https://codurance.com/2020/04/28/terraform-with-multiple-environments/

About

Terraform basics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HCL 100.0%