Complete the code to define a Terraform backend configuration for remote state storage.
terraform {
backend "s3" {
bucket = "[1]"
}
}The bucket specifies the S3 bucket name where Terraform stores the remote state. It must be the actual bucket name used for state storage.
Complete the code to specify the Terraform workspace for environment separation.
terraform {
required_version = ">= 1.0"
}
terraform workspace select [1]Workspaces help separate environments. Here, selecting dev workspace isolates development state.
Fix the error in the pipeline script to apply Terraform only after planning.
steps:
- name: Terraform Plan
run: terraform plan -out=plan.tfplan
- name: Terraform Apply
run: terraform apply [1]The apply command requires the plan file name to apply the exact planned changes. The correct syntax is terraform apply plan.tfplan.
Fill both blanks to configure separate backend buckets and workspaces for dev and prod environments.
terraform {
backend "s3" {
bucket = "[1]"
}
}
terraform workspace select [2]Use dev-terraform-state bucket and development workspace to separate dev environment state.
Fill all three blanks to define a pipeline step that initializes Terraform, selects the correct workspace, and applies the plan.
steps:
- name: Terraform Init
run: terraform init -backend-config=bucket=[1]
- name: Select Workspace
run: terraform workspace select [2]
- name: Terraform Apply
run: terraform apply [3]The init step uses the production bucket, the workspace is set to production, and the apply uses the plan file.