0
0
Terraformcloud~10 mins

Zero-downtime deployment pattern 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" "app_server" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "[1]"
}
Drag options to blanks, or click blank then click option'
Ac5.xlarge
Bt2.micro
Cm5.large
Dt3.micro
Attempts:
3 left
💡 Hint
Common Mistakes
Using an instance type that is too large for simple applications.
Using an instance type that is deprecated or unavailable in the region.
2fill in blank
medium

Complete the code to create an AWS Elastic Load Balancer (ELB) resource.

Terraform
resource "aws_elb" "app_elb" {
  name               = "app-elb"
  availability_zones = ["us-west-2a", "us-west-2b"]
  listener {
    instance_port     = 80
    instance_protocol = "HTTP"
    lb_port           = [1]
    lb_protocol       = "HTTP"
  }
}
Drag options to blanks, or click blank then click option'
A443
B8080
C80
D22
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 443 without configuring HTTPS.
Using a non-standard port that clients won't connect to.
3fill in blank
hard

Fix the error in the code to properly attach instances to the ELB.

Terraform
resource "aws_elb_attachment" "app_attachment" {
  elb      = aws_elb.app_elb.name
  instance = [1]
}
Drag options to blanks, or click blank then click option'
Aaws_instance.app_server.public_dns
Baws_instance.app_server.id
Caws_instance.app_server.private_ip
Daws_instance.app_server.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using the instance name or IP instead of the ID.
Using an attribute that does not uniquely identify the instance.
4fill in blank
hard

Fill both blanks to create a lifecycle rule that prevents Terraform from destroying the old instance immediately.

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

  lifecycle {
    [1] = true
    [2]  = true
  }
}
Drag options to blanks, or click blank then click option'
Acreate_before_destroy
Bprevent_destroy
Cignore_changes
Dreplace_triggered_by
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'ignore_changes' with lifecycle control.
Not using 'create_before_destroy' causing downtime.
5fill in blank
hard

Fill all three blanks to define a Terraform output that shows the ELB DNS name after deployment.

Terraform
output "elb_dns_name" {
  value = [1].[2].[3]
}
Drag options to blanks, or click blank then click option'
Aaws_elb
Bapp_elb
Cdns_name
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'dns_name' for the ELB attribute.
Mixing resource names or types incorrectly.