gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.01k stars 971 forks source link

Terragrunt output dependency variables not being picked up #2289

Open adithyagcp opened 2 years ago

adithyagcp commented 2 years ago

I'm trying to create secret manager and trying to understand how to work with terragrunt output dependencies, I'm working gcp secret manager and secret version as examples My root module looks like this secret_manager_secret.tf

resource "google_secret_manager_secret" "iap_client_secret" {
  secret_id = var.secret_id
  replication {
    automatic = true
  }
  project = var.project
}

output "name" {
value = google_secret_manager_secret.iap_client_secret.name
}

variable "secret_id" {  
}
variable "project" {  
}

secret_version.tf

resource "google_secret_manager_secret_version" "iap_secret_version" {
  secret      = var.secret
  secret_data = var.secret_data
}
variable "secret" {
    type = any 
}

variable "secret_data" {
    type = any
    default = "secret-data"
}

Terragrunt code is as follows secret_manager/terragrunt.hcl

include "root" {
  path = find_in_parent_folders()
}

terraform {
  source = "../../../modules/secret_manager_secret/"
}
locals {
 root_vars   = read_terragrunt_config(find_in_parent_folders())
 common_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
  vars        = read_terragrunt_config("vars.hcl")
}

inputs = merge(
  local.root_vars.inputs,
  local.common_vars.inputs,
  local.vars.inputs
)

vars.hcl

inputs = { 
secret_id = "test_secret"
project = "check-terragrunt-sb"
}

secret_version\terragrunt.hcl

include "root" {
  path = find_in_parent_folders()
}

terraform {
  source = "../../../modules/secret_version/"
}

dependencies {
  paths = ["../secret_manager"]
}

dependency "id" {
  config_path = "../secret_manager"
}

inputs =  {
    secret = dependency.id.outputs.name
  }

I get the following error when I run terragrunt apply-all even though i point to the right output dependency, Why is that?

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # google_secret_manager_secret.iap_client_secret will be created
  + resource "google_secret_manager_secret" "iap_client_secret" {
      + create_time = (known after apply)
      + expire_time = (known after apply)
      + id          = (known after apply)
      + name        = (known after apply)
      + project     = "check-terragrunt-sb"
      + secret_id   = "test_secret"

      + replication {
          + automatic = true
        }
    }

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

Changes to Outputs:
  + name = (known after apply)
google_secret_manager_secret.iap_client_secret: Creating...
google_secret_manager_secret.iap_client_secret: Creation complete after 1s [id=projects/check-terragrunt-sb/secrets/test_secret]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

name = "projects/1079975224630/secrets/test_secret"
time=2022-09-22T19:53:44-07:00 level=warning msg=No double-slash (//) found in source URL C:/Users/adeq/gitlab/test-sb/modules/secret_manager_secret. Relative paths in downloaded Terraform code may not work. prefix=[C:\Users\adeq\gitlab\test-sb\env\nonprod\secret_manager]
time=2022-09-22T19:53:45-07:00 level=warning msg=No double-slash (//) found in source URL C
name = "projects/1079975224630/secrets/test_secret"
time=2022-09-22T19:53:44-07:00 level=warning msg=No double-slash (//) found in source URL C:/Users/adeq/gitlab/test-sb/modules/secret_manager_secret. Relative paths in downloaded Terraform code may not work. prefix=[C:\Users\adeq\gitlab\test-sb\env\nonprod\secret_manager]
time=2022-09-22T19:53:45-07:00 level=warning msg=No double-slash (//) found in source URL C:/Users/adeq/gitlab/test-sb/modules/secret_version. Relative paths in downloaded Terraform code may not work. prefix=[C:\Users\adeq\gitlab\test-sb\env\nonprod\secret_version]
╷
│ Error: Variables not allowed
│
│   on <value for var.secret> line 1:
│   (source code not available)
│
│ Variables may not be used here.
╵
╷
│ Error: Variables not allowed
│
│   on <value for var.secret> line 1:
│   (source code not available)
│
│ Variables may not be used here.
╵
╷
│ Error: Variables not allowed
│
│   on <value for var.secret> line 1:
│   (source code not available)
│
│ Variables may not be used here.
╵
denis256 commented 2 years ago

Hi, it is not clear which is the error during execution... it is "warning msg=No double-slash (//) found in source URL" message?

adithyagcp commented 2 years ago

Sorry for that, Edited the ouput again. Thank You

adithyaGR commented 2 years ago

Please close this issue, was able to find a fix. Thanks

orelf-cw commented 1 year ago

Please close this issue, was able to find a fix. Thanks

@adithyaGR could you please share the fix?