Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unsupported attribute; This object does not have an attribute named" : Issue with terragrunt init not populating state for a dependent module #3889

Open
kami379 opened this issue Feb 14, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@kami379
Copy link

kami379 commented Feb 14, 2025

Describe the bug

I am running terragrunt init for four modules. The first two modules execute successfully, and their respective state.tf files contain the expected resources and outputs.

However, the third module, which depends on the first and second modules, ends up with an empty state.tf (no resources, no outputs), even though there are many resources that should be created. However, this causes an error when creating the fourth module, and later during terragrunt plan and apply...

Why does the third module's state.tf remain empty after init, even though the resources are displayed in the plan and apply logs?

Steps To Reproduce

terragrunt run -all init

Expected behavior

The state file for the third module contains all resources and defined outputs, so the fourth module initializes successfully, and terragrunt plan and apply execute successfully

Versions

  • terraform version: 1.5.3
  • ashicorp/azurerm : v3.90.0

Additional context

Logs error:

Debug Output
18418Z Initializing the backend...
18623Z 
19177Z Initializing provider plugins...
19938Z - Reusing previous version of hashicorp/azurerm from the dependency lock file
20808Z - Reusing previous version of hashicorp/random from the dependency lock file
21628Z - Using previously-installed hashicorp/azurerm v3.90.0
22535Z - Using previously-installed hashicorp/random v3.4.3
23008Z 
23720Z Terraform has been successfully initialized!
24391Z 
24877Z You may now begin working with Terraform. Try running "terraform plan" to see
25733Z any changes that are required for your infrastructure. All Terraform commands
26260Z should now work.
26436Z 
26893Z If you ever set or change modules or backend configuration for Terraform,
27594Z rerun this command to reinitialize your working directory. If you forget, other
28660Z commands will detect it and remind you to do so if necessary.
28948Z 
29733Z time=Z level=error msg=1 error occurred:
31176Z 	* /azp/_work/r1/a/_IaC-AzureKubernetesService/drop/s/environments/dev/azureKubernetesServiceNamespace/terragrunt.hcl:43,78-87: Unsupported attribute; This object does not have an attribute named "aks_name".
31839Z 
31985Z 
33026Z time=Z level=error msg=Unable to determine underlying exit code, so Terragrunt will exit with error code 1
65011Z ##[error]Script failed with exit code: 1
73998Z [command]/usr/bin/az account clear

The module's state file :

{
  "version": 4,
  "terraform_version": "1.5.3",
  "serial": 1,
  "lineage": "vbf6d4--bW52-vfi0-aa6dh34fb0",
  "outputs": {},
  "resources": [],
  "check_results": null
}

terragrunt.hcl for this module:

include {
  path = find_in_parent_folders()
}

terraform {
  source = "git::https://........................."
}

dependency "resourceGroup" {
  config_path = "../resourceGroup"
  mock_outputs = {
    resource_group_name     = "temporary-dummy-resourceGroupName"
    resource_group_location = "westeurope"
  }
}

dependency "random" {
  config_path = "../random"
  mock_outputs = {
    random_result = "abcd5"
  }
}

dependencies {
  paths = ["../resourceGroup", "../random"]
}

locals {
  environmentSpecific = read_terragrunt_config(find_in_parent_folders("environmentSpecific.hcl"))
  environmentGlobal   = read_terragrunt_config(find_in_parent_folders("environmentGlobal.hcl"))
}

inputs = {
  # parameter to create aks
  aks_resource_group_name = dependency.resourceGroup.outputs.resource_group_name
  aks_location            = dependency.resourceGroup.outputs.resource_group_location
  aks_name                = join("", [local.environmentSpecific.locals.aks_name, "-", dependency.random.outputs.random_result])
  aks_dns_prefix          = join("", [local.environmentSpecific.locals.aks_dns_prefix, "-", dependency.random.outputs.random_result])
  aks_sku_tier            = local.environmentSpecific.locals.aks_sku_tier
  aks_pool_default        = local.environmentSpecific.locals.aks_pool_default
  aks_pools               = local.environmentSpecific.locals.aks_pools

  # parameter to create keyvault
  key_vault_resource_group_name                 = dependency.resourceGroup.outputs.resource_group_name
  key_vault_location                            = dependency.resourceGroup.outputs.resource_group_location
  key_vault_name                                = join("", [local.environmentSpecific.locals.key_vault_name, dependency.random.outputs.random_result])
  key_vault_list_objectid_authorized_for_secret = local.environmentSpecific.locals.key_vault_list_objectid_authorized_for_secret

  # subnet information
  subnet_resource_group_name  = local.environmentSpecific.locals.subnet_resource_group_name
  subnet_virtual_network_name = local.environmentSpecific.locals.subnet_virtual_network_name
  subnet_name                 = local.environmentSpecific.locals.subnet_name

  # acr information
  acr_resource_group_name = local.environmentSpecific.locals.acr_resource_group_name
  acr_name                = local.environmentSpecific.locals.acr_name

  tags = merge(
    local.environmentGlobal.locals.tags,
    local.environmentSpecific.locals.tags
  )
}
@kami379 kami379 added the bug Something isn't working label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant