0
0
Terraformcloud~10 mins

Immutable infrastructure concept 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 new AWS EC2 instance resource.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "[1]"
}
Drag options to blanks, or click blank then click option'
Am5.large
Bt3.micro
Ct2.micro
Dc5.xlarge
Attempts:
3 left
💡 Hint
Common Mistakes
Using instance types that are too large for simple examples.
Typo in instance type string.
2fill in blank
medium

Complete the code to add a tag to the AWS instance for identification.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t3.micro"

  tags = {
    Name = "[1]"
  }
}
Drag options to blanks, or click blank then click option'
AMyServer
BOldServer
CTemporary
DProduction
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving the tag value empty.
Using names that are not descriptive.
3fill in blank
hard

Fix the error in the code to ensure immutable infrastructure by replacing the instance on change.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t3.micro"

  lifecycle {
    [1] = true
  }
}
Drag options to blanks, or click blank then click option'
Aprevent_destroy
Breplace_triggered_by
Cignore_changes
Dcreate_before_destroy
Attempts:
3 left
💡 Hint
Common Mistakes
Using prevent_destroy which blocks deletion.
Ignoring changes instead of replacing.
4fill in blank
hard

Fill both blanks to create a new versioned AMI and use it in the instance resource.

Terraform
resource "aws_ami" "example_ami" {
  name                = "example-ami-[1]"
  virtualization_type = "hvm"
  root_device_name    = "/dev/sda1"
  ebs_block_device {
    device_name = "/dev/sda1"
    volume_size = 8
  }
}

resource "aws_instance" "example" {
  ami           = aws_ami.example_ami.[2]
  instance_type = "t3.micro"
}
Drag options to blanks, or click blank then click option'
Av1
Bid
Carn
Dlatest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'latest' which is not an attribute of aws_ami resource.
Using 'arn' instead of 'id' for AMI reference.
5fill in blank
hard

Fill all three blanks to define a Terraform output that shows the public IP of the new instance.

Terraform
output "instance_public_ip" {
  value = aws_instance.example.[1]
  description = "[2] of the instance"
  sensitive = [3]
}
Drag options to blanks, or click blank then click option'
Apublic_ip
BPublic IP address
Cfalse
Dprivate_ip
Attempts:
3 left
💡 Hint
Common Mistakes
Using private_ip instead of public_ip.
Marking output as sensitive when it is not.