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

How do we call submodules from the same terragrunt.hcl file? #3733

Open
manzajohn opened this issue Jan 7, 2025 · 4 comments
Open

How do we call submodules from the same terragrunt.hcl file? #3733

manzajohn opened this issue Jan 7, 2025 · 4 comments

Comments

@manzajohn
Copy link

manzajohn commented Jan 7, 2025

0

I was trying to migrate eks module from version 19 to 20, seems like there is a new submodule got introduced aws_auth in terraform aws eks module and need to remove aws_auth details from eks module. My current terragrunt.hcl file looks like this

terraform {
source = "tfr:///terraform-aws-modules/eks/aws//.?version=${local.source_version}"
}
inputs = {''''}

How can i call this new submodule from the same terragrunt file?

https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest/submodules/aws-auth
from the same terragrunt.hcl file? or what is the best way to achieve this?

i tried to create a separate folder and own terragrunt.hcl file like below

terraform {
source = "tfr:///terraform-aws-modules/eks/aws//modules/aws-auth//.?version=${local.source_version}"
}
inputs = {

version = "~> 20.0"
aws_eks_cluster                              = try(local.eks_outputs.cluster_name.value, "")
manage_aws_auth_configmap = true

aws_auth_roles = local.maproles

}

Also i have added dependency as eks module in this file but still
This gave me below error while terragrunt plan

Error: Reference to undeclared resource │ │ on k8s-provider.tf line 4, in provider "kubernetes": │ 4: host = try(aws_eks_cluster.this[0].endpoint, null) │ │ A managed resource "aws_eks_cluster" "this" has not been declared in the │ root module.

What is the best solution for this?

@yhakbar
Copy link
Collaborator

yhakbar commented Jan 7, 2025

Hey @manzajohn ,

Try this:

terraform {
  source = "tfr:///terraform-aws-modules/eks/aws//modules/aws-auth?version=${local.source_version}"
}

I'm not sure that version input is doing anything, FYI.

@manzajohn
Copy link
Author

manzajohn commented Jan 7, 2025

That is what i tried in the separate terragrunt.hcl file, which throws the above error, my eks_cluster hcl file is having below

terraform {
source = "tfr:///terraform-aws-modules/eks/aws//.?version=${local.source_version}"
}

@yhakbar
Copy link
Collaborator

yhakbar commented Jan 7, 2025

Notice that the file above has this:

tfr:///terraform-aws-modules/eks/aws//modules/aws-auth//.?version=${local.source_version}

Not this:

tfr:///terraform-aws-modules/eks/aws//modules/aws-auth?version=${local.source_version}

@manzajohn
Copy link
Author

manzajohn commented Jan 7, 2025

yes, tried the same, still same error
14:09:25.672 STDERR [aws_auth] terraform: │ Error: Reference to undeclared resource 14:09:25.672 STDERR [aws_auth] terraform: │ 14:09:25.672 STDERR [aws_auth] terraform: │ on k8s-provider.tf line 4, in provider "kubernetes": 14:09:25.672 STDERR [aws_auth] terraform: │ 4: host = try(aws_eks_cluster.this[0].endpoint, null) 14:09:25.672 STDERR [aws_auth] terraform: │ 14:09:25.672 STDERR [aws_auth] terraform: │ A managed resource "aws_eks_cluster" "this" has not been declared in the 14:09:25.672 STDERR [aws_auth] terraform: │ root module.

I can see the errored file in cache folder


`# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa

provider "kubernetes" {
  host                   = try(aws_eks_cluster.this[0].endpoint, null)
  cluster_ca_certificate = base64decode(try(aws_eks_cluster.this[0].certificate_authority[0].data, "="))
  exec {
    api_version = "client.authentication.k8s.io/v1beta1"
    command     = "aws"
    # This requires the awscli to be installed locally where Terraform is executed
    args = ["eks", "get-token", "--cluster-name", try(aws_eks_cluster.this[0].name, ""), "--region", "us-west-2", "--role", ""]
  }
}
`

But as per the module example no such parameters are passed
https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest/submodules/aws-auth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants