Bird
Raised Fist0
Terraformcloud~5 mins

Module versioning in Terraform - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is module versioning in Terraform?
Module versioning in Terraform means keeping track of different versions of a module so you can use a specific, stable version in your infrastructure code.
Click to reveal answer
beginner
Why should you use versioned modules in Terraform?
Using versioned modules helps avoid unexpected changes by locking your infrastructure to a tested module version, making your deployments more reliable.
Click to reveal answer
beginner
How do you specify a module version in Terraform?
You specify a module version by adding a version argument in the module block, like:
module "example" {
source = "registry.terraform.io/hashicorp/example"
version = "1.2.0"
}
Click to reveal answer
intermediate
What happens if you don’t specify a module version?
If you don’t specify a version, Terraform uses the latest available module version, which might cause unexpected changes if the module updates.
Click to reveal answer
intermediate
How can you update a module to a newer version safely?
To update safely, change the version number in your module block, run terraform init -upgrade to download the new version, then test your infrastructure.
Click to reveal answer
What is the purpose of specifying a module version in Terraform?
ATo lock the module to a specific stable version
BTo automatically upgrade to the latest module version
CTo delete old versions of the module
DTo run the module faster
Which command updates Terraform modules to the latest allowed version?
Aterraform destroy
Bterraform apply
Cterraform plan
Dterraform init -upgrade
What happens if you omit the version argument in a Terraform module source?
ATerraform uses the latest module version
BTerraform throws an error
CTerraform uses a random module version
DTerraform disables the module
Why is it risky to always use the latest module version without specifying a version?
AIt disables module caching
BIt makes Terraform run slower
CIt can cause unexpected infrastructure changes
DIt deletes your state file
How do you specify a module version in Terraform code?
Asource_version = "1.0.0" inside the provider block
Bversion = "1.0.0" inside the module block
Cmodule_version = "1.0.0" outside the module block
Dversion = "latest" inside the resource block
Explain what module versioning is in Terraform and why it is important.
Think about how using a fixed version helps keep your infrastructure predictable.
You got /3 concepts.
    Describe the steps to safely update a Terraform module to a newer version.
    Consider how you control the version and apply the update carefully.
    You got /3 concepts.

      Practice

      (1/5)
      1. What is the main purpose of specifying a version when using a Terraform module from a registry?
      easy
      A. To speed up Terraform plan execution
      B. To enable local module usage
      C. To automatically update the module to the latest version
      D. To keep your infrastructure stable by locking the module version

      Solution

      1. Step 1: Understand module versioning purpose

        Specifying a version locks the module to a specific release, preventing unexpected changes.
      2. Step 2: Compare options

        Only locking the version ensures stability; automatic updates or speed improvements are not guaranteed by versioning.
      3. Final Answer:

        To keep your infrastructure stable by locking the module version -> Option D
      4. Quick Check:

        Module versioning = Stability [OK]
      Hint: Version locks module to prevent unexpected changes [OK]
      Common Mistakes:
      • Thinking version speeds up execution
      • Assuming version auto-updates modules
      • Confusing local modules with versioned modules
      2. Which of the following is the correct syntax to specify a module version from the Terraform Registry?
      easy
      A. module "example" { source = "registry/module" version = "1.2.0" }
      B. module "example" { source = "registry/module" ver = "1.2.0" }
      C. module "example" { source = "registry/module" version: "1.2.0" }
      D. module "example" { source = "registry/module" v = "1.2.0" }

      Solution

      1. Step 1: Recall correct version attribute

        The correct attribute to specify module version is version with an equals sign.
      2. Step 2: Check syntax correctness

        module "example" { source = "registry/module" version = "1.2.0" } uses correct attribute and syntax; others use incorrect attribute names or syntax.
      3. Final Answer:

        module "example" { source = "registry/module" version = "1.2.0" } -> Option A
      4. Quick Check:

        Correct attribute is version = "x.y.z" [OK]
      Hint: Use 'version = "x.y.z"' exactly for module versions [OK]
      Common Mistakes:
      • Using 'ver' or 'v' instead of 'version'
      • Using colon instead of equals sign
      • Omitting quotes around version number
      3. Given this Terraform module block:
      module "network" {
        source  = "terraform-aws-modules/vpc/aws"
        version = "3.0.0"
      }

      What happens if a newer version 3.1.0 is released and you run terraform init without changing the version?
      medium
      A. Terraform upgrades the module to version 3.1.0 automatically
      B. Terraform uses version 3.0.0 and does not upgrade automatically
      C. Terraform throws an error about version mismatch
      D. Terraform ignores the version and uses the latest

      Solution

      1. Step 1: Understand version locking behavior

        Specifying version "3.0.0" locks the module to that exact version.
      2. Step 2: Effect of terraform init

        Running terraform init downloads the locked version; it does not upgrade unless version is changed.
      3. Final Answer:

        Terraform uses version 3.0.0 and does not upgrade automatically -> Option B
      4. Quick Check:

        Locked version stays fixed until changed [OK]
      Hint: Locked version stays fixed unless manually updated [OK]
      Common Mistakes:
      • Assuming terraform init upgrades modules automatically
      • Expecting errors on version mismatch
      • Thinking latest version is always used
      4. You have this module block:
      module "db" {
        source = "git::https://github.com/example/db-module.git"
      }

      You want to use a specific version tag v1.4.2. What is missing?
      medium
      A. Add tag = "v1.4.2" inside the block
      B. Add version = "v1.4.2" inside the block
      C. Add ?ref=v1.4.2 to the source URL
      D. Nothing, it uses latest by default

      Solution

      1. Step 1: Understand versioning for Git modules

        Git modules use URL query parameter ?ref= to specify version or tag.
      2. Step 2: Identify correct way to specify tag

        Adding ?ref=v1.4.2 to source URL locks module to that tag.
      3. Final Answer:

        Add ?ref=v1.4.2 to the source URL -> Option C
      4. Quick Check:

        Git module version = source URL + ?ref=tag [OK]
      Hint: Use ?ref=tag in Git source URL for versioning [OK]
      Common Mistakes:
      • Using version attribute for Git modules
      • Using tag attribute which does not exist
      • Assuming latest is always used without specifying ref
      5. You have a local module at ./modules/app and a remote module from the registry. You want to ensure only the remote module uses versioning. How should you configure the modules?
      hard
      A. Specify version only for the remote module; omit for local module
      B. Specify version for both local and remote modules
      C. Specify version only for the local module
      D. Omit version for both modules

      Solution

      1. Step 1: Recall versioning rules for local modules

        Local modules do not support versioning; version attribute is ignored or causes error.
      2. Step 2: Apply version only to remote modules

        Only remote modules from registries or Git support versioning and require version locking.
      3. Final Answer:

        Specify version only for the remote module; omit for local module -> Option A
      4. Quick Check:

        Version only for remote modules [OK]
      Hint: Version attribute only for remote modules, never local [OK]
      Common Mistakes:
      • Adding version to local modules causing errors
      • Omitting version for remote modules causing instability
      • Confusing local and remote module versioning rules
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard