This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Declare the aws provider | |
| provider "aws" { | |
| region = var.aws_region | |
| } | |
| # Create a random id | |
| resource "random_id" "tf_bucket_id" { | |
| byte_length = 2 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| variable "project_name" { | |
| type = map | |
| description = "Name of the project." | |
| default = { | |
| dev = "ga-terraform-dev" | |
| prod = "ga-terraform-prod" | |
| } | |
| } | |
| variable "aws_region" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ terraform destroy -var 'env=prod' | |
| random_id.tf_bucket_id: Refreshing state... [id=HQw] | |
| aws_s3_bucket.tf_code: Refreshing state... [id=ga-terraform-prod-7436] | |
| An execution plan has been generated and is shown below. | |
| Resource actions are indicated with the following symbols: | |
| - destroy | |
| Terraform will perform the following actions: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ terraform destroy -var 'env=dev' | |
| random_id.tf_bucket_id: Refreshing state... [id=OkE] | |
| aws_s3_bucket.tf_code: Refreshing state... [id=ga-terraform-dev-14913] | |
| An execution plan has been generated and is shown below. | |
| Resource actions are indicated with the following symbols: | |
| - destroy | |
| Terraform will perform the following actions: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ tree | |
| . | |
| |-- main.tf | |
| |-- outputs.tf | |
| |-- terraform.tfstate.d | |
| | |-- dev | |
| | | `-- terraform.tfstate | |
| | `-- prod | |
| | `-- terraform.tfstate | |
| |-- terraform.tfvars |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ terraform apply "tfprod_plan" | |
| random_id.tf_bucket_id: Creating... | |
| random_id.tf_bucket_id: Creation complete after 0s [id=HQw] | |
| aws_s3_bucket.tf_code: Creating... | |
| aws_s3_bucket.tf_code: Still creating... [10s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [20s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [30s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [40s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [50s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [1m0s elapsed] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ terraform plan -out=tfprod_plan -var 'env=prod' | |
| Refreshing Terraform state in-memory prior to plan... | |
| The refreshed state will be used to calculate this plan, but will not be | |
| persisted to local or remote state storage. | |
| ------------------------------------------------------------------------ | |
| An execution plan has been generated and is shown below. | |
| Resource actions are indicated with the following symbols: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ terraform apply "tfdev_plan" | |
| random_id.tf_bucket_id: Creating... | |
| random_id.tf_bucket_id: Creation complete after 0s [id=OkE] | |
| aws_s3_bucket.tf_code: Creating... | |
| aws_s3_bucket.tf_code: Still creating... [10s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [20s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [30s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [40s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [50s elapsed] | |
| aws_s3_bucket.tf_code: Still creating... [1m0s elapsed] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ terraform plan -out=tfdev_plan -var 'env=dev' | |
| Refreshing Terraform state in-memory prior to plan... | |
| The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. | |
| ------------------------------------------------------------------------ | |
| An execution plan has been generated and is shown below. | |
| Resource actions are indicated with the following symbols: | |
| + create |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ terraform init | |
| Initializing the backend... | |
| Initializing provider plugins... | |
| - Checking for available provider plugins... | |
| - Downloading plugin for provider "google" (hashicorp/google) 3.25.0... | |
| Terraform has been successfully initialized! | |
| You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. | |
| If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. |