0
0
Terraformcloud~10 mins

Terraform_remote_state usage - 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 in Terraform.

Terraform
data "terraform_remote_state" "example" {
  backend = "[1]"
  config = {
    bucket = "my-terraform-state"
    key    = "state.tfstate"
    region = "us-east-1"
  }
}
Drag options to blanks, or click blank then click option'
Alocal
Bazurerm
Cs3
Dgcs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' instead of 's3' for remote state backend.
Confusing backend names with provider names.
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.[1]["vpc_id"]
}
Drag options to blanks, or click blank then click option'
Aoutputs
Bresources
Cvariables
Dmodules
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'resources' or 'variables' instead of 'outputs'.
Trying to access outputs directly without the 'outputs' attribute.
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/terraform.tfstate"
    region = "us-west-2"
  }
}
Drag options to blanks, or click blank then click option'
Agcs
Bs3
Cazurerm
Dlocal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' backend when remote state is stored in S3.
Using 'gcs' or 'azurerm' for AWS S3 buckets.
4fill in blank
hard

Fill both blanks to correctly define a remote state data source for Azure Blob Storage.

Terraform
data "terraform_remote_state" "storage" {
  backend = "[1]"
  config = {
    container_name = "tfstate"
    key            = "storage.tfstate"
    [2]      = "my-storage-account"
  }
}
Drag options to blanks, or click blank then click option'
Aazurerm
Bbucket
Cstorage_account_name
Dregion
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bucket' instead of 'storage_account_name' for Azure backend.
Using 'region' which is not required for Azure backend config.
5fill in blank
hard

Fill all three blanks to correctly access a remote state output named 'subnet_ids' and assign it to a local variable.

Terraform
locals {
  subnet_ids = data.terraform_remote_state.network.[1][[2]]
  count      = length(local.subnet_ids) [3] 0
}
Drag options to blanks, or click blank then click option'
Aoutputs
B"subnet_ids"
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using variables or resources instead of outputs.
Not quoting the output key string.
Using '<' instead of '>' for comparison.