0
0
Terraformcloud~10 mins

Blue-green infrastructure 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 the active environment variable for blue-green deployment.

Terraform
variable "active_environment" {
  type    = string
  default = "[1]"
}
Drag options to blanks, or click blank then click option'
Ablue
Bgreen
Cred
Dyellow
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the default to an undefined environment like "red" or "yellow".
Leaving the default empty.
2fill in blank
medium

Complete the code to create a resource group for the green environment.

Terraform
resource "azurerm_resource_group" "green" {
  name     = "rg-[1]"
  location = var.location
}
Drag options to blanks, or click blank then click option'
Aprod
Bgreen
Cblue
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using "blue" instead of "green" for the green environment resource group.
Using unrelated names like "prod" or "test".
3fill in blank
hard

Fix the error in the code to select the inactive environment correctly.

Terraform
locals {
  inactive_environment = var.active_environment == "blue" ? "[1]" : "blue"
}
Drag options to blanks, or click blank then click option'
Agreen
Bblue
Cprod
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Setting inactive environment to "blue" when active is "blue".
Using unrelated environment names.
4fill in blank
hard

Fill both blanks to define the load balancer backend pool for the active environment.

Terraform
resource "azurerm_lb_backend_address_pool" "active_pool" {
  name                = "lb-backend-[1]"
  resource_group_name = azurerm_resource_group.[2].name
  loadbalancer_id     = azurerm_lb.main.id
}
Drag options to blanks, or click blank then click option'
Aactive_environment
Bgreen
Cblue
Dinactive_environment
Attempts:
3 left
💡 Hint
Common Mistakes
Using inactive environment name in the backend pool.
Referencing the resource group incorrectly.
5fill in blank
hard

Fill all three blanks to switch traffic to the inactive environment by updating the active environment variable and resource group references.

Terraform
variable "active_environment" {
  default = "[1]"
}

resource "azurerm_resource_group" "[2]" {
  name     = "rg-[3]"
  location = var.location
}
Drag options to blanks, or click blank then click option'
Agreen
Bblue
Attempts:
3 left
💡 Hint
Common Mistakes
Not updating the active environment variable.
Mismatching resource group names.