Bird
Raised Fist0
Terraformcloud~10 mins

Resource documentation reference in Terraform - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the Terraform provider source.

Terraform
terraform {
  required_providers {
    aws = {
      source = "[1]"
    }
  }
}
Drag options to blanks, or click blank then click option'
Ahashicorp/aws
Baws/hashicorp
Cterraform/aws
Dprovider/aws
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect source format like 'aws/hashicorp'.
Confusing provider name with source.
2fill in blank
medium

Complete the code to reference the official Terraform AWS provider documentation URL.

Terraform
Documentation URL: https://registry.terraform.io/providers/[1]/latest/docs
Drag options to blanks, or click blank then click option'
Aaws/hashicorp
Bhashicorp/aws
Cterraform/aws
Dprovider/aws
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of namespace and provider name.
Using incorrect provider names in the URL.
3fill in blank
hard

Fix the error in the resource block by completing the resource type correctly.

Terraform
resource "[1]" "example" {
  bucket = "my-bucket"
  acl    = "private"
}
Drag options to blanks, or click blank then click option'
Abucket_aws_s3
Bs3_bucket_aws
Caws.bucket.s3
Daws_s3_bucket
Attempts:
3 left
💡 Hint
Common Mistakes
Using dots instead of underscores.
Reversing provider and resource names.
4fill in blank
hard

Fill both blanks to complete the provider configuration with region and version.

Terraform
provider "aws" {
  region  = "[1]"
}

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "[2]"
    }
  }
}
Drag options to blanks, or click blank then click option'
Aus-west-2
B1.0.0
Clatest
Deu-central-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'latest' as version in provider block (should be in required_providers).
Using invalid region names.
5fill in blank
hard

Fill all three blanks to complete the resource block with name, bucket, and ACL.

Terraform
resource "aws_s3_bucket" "[1]" {
  bucket = "[2]"
  acl    = "[3]"
}
Drag options to blanks, or click blank then click option'
Amy_bucket
Bmy-bucket
Cprivate
Dpublic-read
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid resource names with hyphens.
Confusing resource name with bucket name.
Setting ACL to unsupported values.

Practice

(1/5)
1. What is the main purpose of Terraform resource documentation?
easy
A. To explain how to install Terraform on your computer
B. To provide pricing details for cloud services
C. To list all cloud providers available
D. To show how to configure cloud resources correctly

Solution

  1. Step 1: Understand the role of resource documentation

    Resource documentation explains how to write code to create and manage cloud resources safely and correctly.
  2. Step 2: Identify the correct purpose among options

    Only To show how to configure cloud resources correctly matches this purpose; others talk about pricing, providers, or installation, which are not the main focus.
  3. Final Answer:

    To show how to configure cloud resources correctly -> Option D
  4. Quick Check:

    Resource documentation = configuration guide [OK]
Hint: Docs explain resource setup, not pricing or installation [OK]
Common Mistakes:
  • Confusing documentation with pricing info
  • Thinking docs list all providers
  • Assuming docs explain Terraform installation
2. Which of the following is the correct way to reference the official Terraform documentation for an AWS S3 bucket resource?
easy
A. https://aws.amazon.com/s3/docs/terraform
B. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket
C. https://terraform.io/docs/aws/s3bucket
D. https://docs.aws.amazon.com/terraform/s3_bucket

Solution

  1. Step 1: Identify the official Terraform docs URL pattern

    Terraform official docs use registry.terraform.io with provider and resource paths.
  2. Step 2: Match the correct URL format for AWS S3 bucket

    https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket matches the official pattern exactly; others are incorrect or non-existent URLs.
  3. Final Answer:

    https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket -> Option B
  4. Quick Check:

    Official docs URL = registry.terraform.io [OK]
Hint: Official docs always start with registry.terraform.io [OK]
Common Mistakes:
  • Using AWS service docs instead of Terraform docs
  • Incorrect URL paths or domains
  • Mixing AWS and Terraform documentation URLs
3. Given this Terraform snippet referencing an AWS EC2 instance resource:
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
  tags = {
    Name = "ExampleInstance"
  }
}

According to the official documentation, what attribute is used to specify the instance type?
medium
A. instance_type
B. type_instance
C. ec2_type
D. instanceSize

Solution

  1. Step 1: Check the resource attribute names in the snippet

    The snippet uses 'instance_type' to set the EC2 instance size.
  2. Step 2: Confirm with official docs attribute naming

    Official docs confirm 'instance_type' is the correct attribute; others are invalid.
  3. Final Answer:

    instance_type -> Option A
  4. Quick Check:

    EC2 size attribute = instance_type [OK]
Hint: Look for exact attribute names in official docs [OK]
Common Mistakes:
  • Using incorrect attribute names like 'type_instance'
  • Guessing attribute names without checking docs
  • Confusing AWS console terms with Terraform attributes
4. You wrote this Terraform resource for an AWS S3 bucket:
resource "aws_s3_bucket" "mybucket" {
  bucket = 12345
  acl    = "private"
}

According to the official documentation, what is the error here?
medium
A. The acl attribute is missing
B. The resource type should be aws_bucket_s3
C. The bucket name must be a string, not a number
D. The bucket attribute is optional and can be omitted

Solution

  1. Step 1: Check the bucket attribute type in official docs

    The 'bucket' attribute must be a string representing the bucket name.
  2. Step 2: Identify the error in the code snippet

    The code uses a number (12345) instead of a string, causing a type error.
  3. Final Answer:

    The bucket name must be a string, not a number -> Option C
  4. Quick Check:

    Bucket name type = string [OK]
Hint: Bucket names are strings, always use quotes [OK]
Common Mistakes:
  • Using numbers instead of strings for bucket names
  • Wrong resource type name
  • Assuming bucket attribute is optional
5. You want to create a Terraform configuration for an Azure virtual machine. The official documentation shows the resource as azurerm_linux_virtual_machine with attributes like name, resource_group_name, and size. Which of these is the best practice when writing your Terraform code?
hard
A. Always refer to the official resource documentation to use correct attribute names and required fields
B. Guess attribute names based on Azure portal labels to save time
C. Use any attribute names you prefer as Terraform will auto-correct them
D. Skip reading documentation if you have used Azure before

Solution

  1. Step 1: Understand the importance of official docs

    Official docs provide accurate, up-to-date attribute names and required fields for resources.
  2. Step 2: Evaluate the options for best practice

    Only Always refer to the official resource documentation to use correct attribute names and required fields advises using official docs, ensuring valid and safe infrastructure code.
  3. Final Answer:

    Always refer to the official resource documentation to use correct attribute names and required fields -> Option A
  4. Quick Check:

    Use official docs = best practice [OK]
Hint: Always check official docs before coding resources [OK]
Common Mistakes:
  • Guessing attribute names without docs
  • Assuming Terraform auto-corrects mistakes
  • Skipping docs due to prior experience