0
0
Terraformcloud~10 mins

Mock providers in tests 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 mock provider block in Terraform.

Terraform
provider "mock" {
  [1] = true
}
Drag options to blanks, or click blank then click option'
Atest_mode
Benabled
Cmock_enabled
Dsimulate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'enabled' instead of 'test_mode'
Using 'mock_enabled' which is not a valid argument
Using 'simulate' which is not recognized
2fill in blank
medium

Complete the code to declare a mock resource in Terraform test configuration.

Terraform
resource "mock_resource" "example" {
  name = "test"
  [1] = "mock_value"
}
Drag options to blanks, or click blank then click option'
Aid
Bmock_id
Cresource_id
Dtest_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' which is reserved for real resources
Using 'resource_id' which is not recognized
Using 'test_id' which is invalid
3fill in blank
hard

Fix the error in the mock provider block to enable testing.

Terraform
provider "mock" {
  test_mode = [1]
}
Drag options to blanks, or click blank then click option'
Atrue
B"true"
C1
Dyes
Attempts:
3 left
💡 Hint
Common Mistakes
Using quoted strings like "true" instead of boolean true
Using numeric or string values like 1 or 'yes'
4fill in blank
hard

Fill both blanks to create a mock data source with a test attribute.

Terraform
data "mock_data" "example" {
  [1] = "test"
  [2] = true
}
Drag options to blanks, or click blank then click option'
Aname
Btest_mode
Cenabled
Dmock_enabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'enabled' or 'mock_enabled' instead of 'test_mode'
Confusing the order of attributes
5fill in blank
hard

Fill all three blanks to define a mock provider with a resource and enable test mode.

Terraform
provider "mock" {
  [1] = true
}

resource "mock_resource" "example" {
  [2] = "mock_value"
  [3] = "active"
}
Drag options to blanks, or click blank then click option'
Atest_mode
Bmock_id
Cstatus
Denabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'enabled' instead of 'test_mode' for the provider
Using incorrect attribute names for the resource