Question 1mediummultiple choice
Read the full Implement and maintain state explanation →TF-003 Implement and maintain state • Complete Question Bank
Complete TF-003 Implement and maintain state question bank — all 0 questions with answers and detailed explanations.
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
List resources in the state
Show details of a single resource in state
Move an item in the state
Remove an item from the state
Download current state from backend
$ terraform state list aws_vpc.main aws_subnet.public aws_instance.web
terraform {
backend "s3" {
bucket = "my-company-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
encrypt = true
}
}Error: Error acquiring the state lock Error message: ConditionalCheckFailedException: The conditional request failed Lock Info: ID: 123456 Path: my-company-terraform-state/prod/terraform.tfstate Operation: OperationTypeApply Who: jenkins@ci Version: 1.0.0 Created: 2023-01-15 10:00:00.123456789 +0000 UTC Info: terraform apply from pipeline
$ terraform state list aws_instance.web[0] aws_instance.web[1] aws_instance.web[2] aws_s3_bucket.data
terraform {
backend "s3" {
bucket = "my-company-state-bucket"
key = "dev/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "tf-lock-table"
}
}Error: Error loading state:
Terraform state file does not exist.Refer to the exhibit.
```
$ terraform show
# data.aws_ami.ubuntu
id = "ami-0c55b159cbfafe1f0"
# aws_instance.web
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "WebServer"
}
}
```$ terraform state list aws_instance.web aws_security_group.sg
Error: Backend initialization required: please run "terraform init" Reason: Backend configuration has changed. The configured backend "s3" has changed since the last "terraform init". Previous configuration: bucket = "prod-terraform-state" key = "network/terraform.tfstate" region = "us-east-1" New configuration: bucket = "prod-terraform-state" key = "network/terraform.tfstate" region = "us-west-2"
Error: Error acquiring the state lock Lock Info: ID: 1234567890abcdef Path: terraform.tfstate Operation: OperationTypeInvalid Who: user@hostname Version: 1.0.0 Created: 2023-01-15 10:30:00.000000000 +0000 UTC Info: Terraform acquires a state lock to protect the state from being written by multiple users at the same time. Please resolve the issue and try again. If you have access to the backend, you may be able to unlock it manually by running "terraform force-unlock <lock-id>".
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "WebServer"
}
}
# Remote state data source
data "terraform_remote_state" "network" {
backend = "s3"
config = {
bucket = "mycompany-terraform-state"
key = "network/terraform.tfstate"
region = "us-east-1"
}
}
resource "aws_security_group" "web_sg" {
name_prefix = "web-sg-"
vpc_id = data.terraform_remote_state.network.outputs.vpc_id
}Error: Backend configuration block requires a backend type
on main.tf line 1, in terraform:
1: terraform {
2: backend "s3" {
3: }
4: }
An argument named "region" or "bucket" is required.$ terraform init Initializing the backend... Successfully configured the backend "s3"! Terraform will automatically use this backend for state storage. Initializing provider plugins... - Finding latest version of hashicorp/aws... - Installing hashicorp/aws v4.0.0... - Installed hashicorp/aws v4.0.0 (signed by HashiCorp) Terraform has been successfully initialized! $ terraform plan No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.