0
0
Terraformcloud~10 mins

State locking with DynamoDB 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 DynamoDB table for Terraform state locking.

Terraform
resource "aws_dynamodb_table" "terraform_locks" {
  name           = "terraform-locks"
  billing_mode   = "[1]"
  hash_key       = "LockID"

  attribute {
    name = "LockID"
    type = "S"
  }
}
Drag options to blanks, or click blank then click option'
ASTANDARD
BPROVISIONED
CON_DEMAND
DPAY_PER_REQUEST
Attempts:
3 left
💡 Hint
Common Mistakes
Using PROVISIONED billing mode without specifying read/write capacity units.
Using an invalid billing mode string.
2fill in blank
medium

Complete the backend configuration to enable DynamoDB state locking in Terraform.

Terraform
terraform {
  backend "s3" {
    bucket         = "my-terraform-state"
    key            = "global/s3/terraform.tfstate"
    region         = "us-west-2"
    dynamodb_table = "[1]"
  }
}
Drag options to blanks, or click blank then click option'
Aterraform-locks
Bstate-locks
Cterraform-lock-table
Dterraform-state-lock
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different or misspelled table name.
Leaving the dynamodb_table field empty.
3fill in blank
hard

Fix the error in the DynamoDB table resource by completing the missing attribute type.

Terraform
resource "aws_dynamodb_table" "terraform_locks" {
  name         = "terraform-locks"
  billing_mode = "PAY_PER_REQUEST"
  hash_key     = "LockID"

  attribute {
    name = "LockID"
    type = "[1]"
  }
}
Drag options to blanks, or click blank then click option'
AN
BB
CS
DM
Attempts:
3 left
💡 Hint
Common Mistakes
Using N (number) or B (binary) instead of S (string).
Using M (map) which is not valid for hash keys.
4fill in blank
hard

Fill both blanks to configure the S3 backend with encryption and DynamoDB state locking.

Terraform
terraform {
  backend "s3" {
    bucket         = "my-terraform-state"
    key            = "global/s3/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = [1]
    dynamodb_table = "[2]"
  }
}
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
Cterraform-locks
Dstate-lock-table
Attempts:
3 left
💡 Hint
Common Mistakes
Setting encrypt to false disables encryption.
Using wrong DynamoDB table names.
5fill in blank
hard

Fill all three blanks to define a DynamoDB table with a TTL attribute for automatic lock expiration.

Terraform
resource "aws_dynamodb_table" "terraform_locks" {
  name           = "terraform-locks"
  billing_mode   = "PAY_PER_REQUEST"
  hash_key       = "LockID"

  attribute {
    name = "LockID"
    type = "[1]"
  }

  ttl {
    attribute_name = "[2]"
    enabled        = [3]
  }
}
Drag options to blanks, or click blank then click option'
AS
BExpirationTime
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute type for LockID.
Disabling TTL by setting enabled to false.
Using incorrect TTL attribute name.