Skip to content

Module within module silently ignored until terraform init #21771

@benhoskings

Description

@benhoskings

Terraform Version

0.12.2

G'day, I've found on terraform 0.12.x that a module within a module won't be detected during plan and will be silently ignored until terraform init is run, rather than failing plan like a top-level module does.

Terraform Configuration Files

$ cat target/target.tf
resource "null_resource" "test" {
  provisioner "local-exec" {
    command = "true"
  }
}

module "mod" {
  source = "../module"
}
$ cat module/module.tf
resource "null_resource" "mod_test" {
  provisioner "local-exec" {
    command = "true"
  }
}
$ cat submod/submod.tf
resource "null_resource" "submod_test" {
  provisioner "local-exec" {
    command = "true"
  }
}

If you initialise the above structure, and then modify module/module.tf like so without re-initing:

$ cat module/module.tf
resource "null_resource" "mod_test" {
  provisioner "local-exec" {
    command = "true"
  }
}

module "submod" {
  source = "../submod"
}

Expected behaviour

Error: Module not installed

  on module.tf line 7:
   7: module "submod" {

Actual behaviour

$ terraform plan

# ...

Terraform will perform the following actions:

  # null_resource.test will be created
  + resource "null_resource" "test" {
      + id = (known after apply)
    }

  # module.mod.null_resource.mod_test will be created
  + resource "null_resource" "mod_test" {
      + id = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.

$ terraform init

# ...

$ terraform plan

# ...

Terraform will perform the following actions:

  # null_resource.test will be created
  + resource "null_resource" "test" {
      + id = (known after apply)
    }

  # module.mod.null_resource.mod_test will be created
  + resource "null_resource" "mod_test" {
      + id = (known after apply)
    }

  # module.mod.module.submod.null_resource.submod_test will be created
  + resource "null_resource" "submod_test" {
      + id = (known after apply)
    }

Plan: 3 to add, 0 to change, 0 to destroy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions