Skip to content

Instantly share code, notes, and snippets.

View bharatmicrosystems's full-sized avatar
😀

Gaurav Agarwal bharatmicrosystems

😀
View GitHub Profile
# Declare the aws provider
provider "aws" {
region = var.aws_region
}
# Create a random id
resource "random_id" "tf_bucket_id" {
byte_length = 2
}
variable "project_name" {
type = map
description = "Name of the project."
default = {
dev = "ga-terraform-dev"
prod = "ga-terraform-prod"
}
}
variable "aws_region" {
$ 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:
$ 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:
$ tree
.
|-- main.tf
|-- outputs.tf
|-- terraform.tfstate.d
| |-- dev
| | `-- terraform.tfstate
| `-- prod
| `-- terraform.tfstate
|-- terraform.tfvars
$ 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]
$ 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:
$ 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]
$ 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
$ 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.