TheBlackMini
TheBlackMini

Reputation: 31

Terragrunt - Unsupported attribute --- but tfstate has the attribute

I cannot figure this out, it's happened a couple of times and this time I'm unable to work around it.

The error I'm getting from terragrunt is

terragrunt.hcl:25,47-50: Unsupported attribute; This object does not have an attribute named "id".

My issue is that the id which I'm trying to reference is present in the tfstate, why can it not see it?

Shortened code below terragrunt.hcl

dependency "vm01" {
  config_path = "../vm01"
}

include {
  path = find_in_parent_folders()
}

terraform {
  source = "//core/azurerm_virtual_machine_extension"
}

locals {
  vm_name = "vm01"
}

inputs = {
  name                  = local.vm_name
  virtual_machine_id    = dependency.vm01.id
.....
}

output.hcl

output "id" {
  value = azurerm_windows_virtual_machine.vm.id
}

tfstate pulled directly from backend storage account

{
  "version": 4,
  "terraform_version": "0.14.7",
  "serial": 4,
  "lineage": "abcde-guid-abcde",
  "outputs": {
    "id": {
      "value": "/subscriptions/abcde-guid-abcde/resourceGroups/rg-name/providers/Microsoft.Compute/virtualMachines/vm01",
      "type": "string"
    }
  }
...........
}

Upvotes: 1

Views: 4972

Answers (3)

Eyal Solomon
Eyal Solomon

Reputation: 616

As this is correct for this situation, it can also happen due to output not being available:

In your ../vm01 dependence you need to terragrunt refresh first in order to reflect the output in remote state. After this, it will be available and work when running commands locally.

Upvotes: 3

Daniel Viglione
Daniel Viglione

Reputation: 9407

Another one of the idiosyncrasies of terragrunt. Let’s say you source a module which did not have the output and you are using remote state, and you are running the executions in a CI/CD platform like Github Actions, which updated the remote state.

Then at a later point, you add the output to the original module. You might think since you are sourcing the updated version of the module, e.g. using git tags, it would recognize the outputs. But it won’t if you are using remote state in an s3 bucket, for example. If you run terragrunt apply, instead of terragrunt plan, then it will update the remote state.

This is one of the plethora of gotchas of terragrunt.

Upvotes: 2

TheBlackMini
TheBlackMini

Reputation: 31

Thanks to yorinasub17 over at the terraform github I found my answer.

The outputs are nested under outputs, so the path to id is dependency.vm01.outputs.id, not dependency.vm01.id as you are referencing in the code snippet. See the dependency block reference for more info.

Upvotes: 2

Related Questions