- Infrastructure management with Terraform
- AWS account
- AWS CLI
- Terraform
- IAM user with programmatic access
- AWS credentials and region
-
Create a new IAM user with programmatic access and attach the following policies to the user:
- AmazonEC2FullAccess
- AmazonS3FullAccess (For S3 bucket creation)
-
Generate the access key and secret key for the user and save it in a secure location.
-
Configure the AWS CLI with the access key and secret key.
-
Create a new S3 bucket and enable versioning. S3 bucket can be used to store the terraform state file.
-
Backup the terraform state file in the S3 bucket.
-
Create a new file named
backend.tf
and add the following code:terraform { backend "s3" { bucket = "s3-bucket-name" key = "s3-bucket-key" region = "s3-bucket-region" } }
-
This will create a new file named
terraform.tfstate
in the S3 bucket. This file will be used to store the terraform state file.
-
- Create a new file named
terraform.tfvars
and add the following variables:aws_access_key
- AWS access keyaws_secret_key
- AWS secret keyaws_region
- AWS regions3_bucket_name
- S3 bucket names3_bucket_key
- S3 bucket keys3_bucket_region
- S3 bucket region
- Run the following commands:
terraform init
- To initialize the working directoryterraform refresh
- To update the state file against real resourcesterraform fmt
- To rewrite Terraform configuration files to a canonical format and styleterraform validate
- To validate the configuration filesterraform plan
- To create an execution planterraform apply
- To apply the changes required to reach the desired state of the configurationterraform destroy
- To destroy the Terraform-managed infrastructure
- Azure account
- Azure CLI
- Terraform
- Azure credentials and region
- Azure subscription ID
- Azure tenant ID
- Azure client ID
- Azure client secret
-
Create a new service principal with the following command:
az ad sp create-for-rbac --name "terraform" --role="Contributor" --scopes="/subscriptions/<subscription_id>"
-
Copy the
appId
,password
,tenant
and save it in a secure location. -
Configure the Azure CLI with the
appId
,password
,tenant
andsubscriptionId
. -
Create a new resource group and storage account. Storage account can be used to store the terraform state file.
-
Backup the terraform state file in the storage account.
-
Create a new file named
backend.tf
and add the following code:terraform { backend "azurerm" { resource_group_name = "resource-group-name" storage_account_name = "storage-account-name" container_name = "container-name" key = "storage-account-key" } }
-
This will create a new file named
terraform.tfstate
in the storage account. This file will be used to store the terraform state file. -
Enable versioning for the storage account.
-
- Create a new file named
terraform.tfvars
and add the following variables:azure_subscription_id
- Azure subscription IDazure_tenant_id
- Azure tenant IDazure_client_id
- Azure client IDazure_client_secret
- Azure client secretazure_region
- Azure regionstorage_account_name
- Storage account namestorage_account_key
- Storage account keyresource_group_name
- Resource group namecontainer_name
- Container name
- Run the following commands:
terraform init
- To initialize the working directoryterraform refresh
- To update the state file against real resourcesterraform fmt
- To rewrite Terraform configuration files to a canonical format and styleterraform validate
- To validate the configuration filesterraform plan
- To create an execution planterraform apply
- To apply the changes required to reach the desired state of the configurationterraform destroy
- To destroy the Terraform-managed infrastructure
terraform show
- To show the current state of the infrastructureterraform import
- To import existing infrastructure into Terraformterraform output
- To show the output values from the root moduleterraform console
- To open an interactive console for Terraform interpolationsterraform graph
- To create a visual graph of Terraform resources
- Terraform
- Terraform - Getting Started
- Terraform - AWS Provider
- Terraform - Azure Provider
- Terraform - Azure CLI
- Terraform - Azure CLI - Create Service Principal
- Terraform - Azure CLI - Configure
- Terraform - AWS CLI
- Terraform - AWS CLI - Configure
- Youtube- Terraform Tutorial for Beginners by FreeCodeCamp.org on YouTube (Video)
- YouTube - Terraform AWS by freeCodeCamp.org on YouTube (Video)
- YouTube - Terraform Azure Playlist by Bee a Learner on YouTube (Video)
- Fork the repository
- Clone the forked repository to your local machine
- Create a new branch using git checkout -b
- Make changes to the code
- Commit the changes using git commit -m ""
- Push the changes to your forked repository using git push origin
- Create a pull request
- Wait for your pull request to be reviewed and merged
- Star this repository
- Celebrate - you've just contributed to open source!