0
0
Terraformcloud~10 mins

Remote state data source in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a remote state data source using Terraform.

Terraform
data "terraform_remote_state" "example" {
  backend = "[1]"
  config = {
    bucket = "my-terraform-state"
    key    = "state.tfstate"
    region = "us-west-2"
  }
}
Drag options to blanks, or click blank then click option'
As3
Blocal
Cgcs
Dazurerm
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' instead of a remote backend.
Confusing backend names like 'gcs' for AWS S3.
2fill in blank
medium

Complete the code to access an output named 'vpc_id' from the remote state.

Terraform
output "vpc_id" {
  value = data.terraform_remote_state.example.outputs.[1]
}
Drag options to blanks, or click blank then click option'
AvpcId
Bvpc_id
CVpcId
Dvpcid
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase or PascalCase instead of snake_case.
Misspelling the output name.
3fill in blank
hard

Fix the error in the remote state data source configuration by completing the missing backend name.

Terraform
data "terraform_remote_state" "network" {
  backend = "[1]"
  config = {
    bucket = "network-state"
    key    = "network.tfstate"
    region = "us-east-1"
  }
}
Drag options to blanks, or click blank then click option'
Alocal
Bhttp
Cs3
Dconsul
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' backend for remote state.
Using unsupported backend names.
4fill in blank
hard

Fill both blanks to correctly configure the remote state data source with S3 backend and specify the state file key.

Terraform
data "terraform_remote_state" "app" {
  backend = "[1]"
  config = {
    bucket = "app-state-bucket"
    key    = "[2]"
    region = "us-east-2"
  }
}
Drag options to blanks, or click blank then click option'
As3
Bapp.tfstate
Cstate.tfstate
Dlocal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' as backend for remote state.
Incorrect or generic state file names.
5fill in blank
hard

Fill all three blanks to define a remote state data source with S3 backend, specify the bucket, and access the 'subnet_ids' output.

Terraform
data "terraform_remote_state" "network" {
  backend = "[1]"
  config = {
    bucket = "[2]"
    key    = "network.tfstate"
    region = "us-west-1"
  }
}

output "subnet_ids" {
  value = data.terraform_remote_state.network.outputs.[3]
}
Drag options to blanks, or click blank then click option'
As3
Bnetwork-state-bucket
Csubnet_ids
Dvpc_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong backend names.
Incorrect bucket names.
Accessing outputs with wrong names.