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
7.96k stars 967 forks source link

Sub-Module dependencies for data source #2225

Open tleibovichverint opened 2 years ago

tleibovichverint commented 2 years ago

I want to use Terragrunt to deploy this example: https://github.com/aws-ia/terraform-aws-eks-blueprints/blob/main/examples/complete-kubernetes-addons/main.tf

So far, I was able to create the VPC/EKS resource without a problem, I separated each module into a different module directory, and everything worked as expected.

When I tried to do the same for the Kubernetes-addons module, I faced an issue with the data source trying to call to the cluster and failing since the cluster wasn't created at this point.

Here's my terragrunt.hcl which I'm trying to execute run-all plan with this specific module:

...
terraform { 
  source = "git::git@github.com:aws-ia/terraform-aws-eks-blueprints.git//modules/kubernetes-addons?ref=v4.6.1"
}

locals {
  # Extract needed variables for reuse
  cluster_version = "${include.envcommon.locals.cluster_version}"
  name =  "${include.envcommon.locals.name}"

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

  mock_outputs = {
    eks_cluster_endpoint = "https://000000000000.gr7.eu-west-3.eks.amazonaws.com"
    eks_oidc_provider = "something"
    eks_cluster_id = "something"
  }
}
inputs = {
  eks_cluster_id = dependency.eks.outputs.cluster_id
  eks_cluster_endpoint = dependency.eks.outputs.eks_cluster_endpoint
  eks_oidc_provider = dependency.eks.outputs.eks_oidc_provider
  eks_cluster_version = local.cluster_version
...
}

The error that I'm getting here:
`

INFO[0035]
  Error: error reading EKS Cluster (something): couldn't find resource
   with data.aws_eks_cluster.eks_cluster,
    on data.tf line 7, in data "aws_eks_cluster" "eks_cluster":
      7: data "aws_eks_cluster" "eks_cluster" {

`

If I run it directly from the example, terraform plan worked as expected. Any idea how to workaround this issue?

denis256 commented 2 years ago

Hi, most probably during the execution of run-all plan mock output is passed to the terraform code and it fails trying to read cluster details from provided data...

To avoid this situation, if possible, can be provided valid mock outputs to not break plan execution, not sure if it is possible in this case since it is expected to have already deployed EKS cluster

Eugst commented 1 year ago

good point, but if I would like to create everything from scratch with terragrunt dependencies. Is it possible? For example:

  1. network
  2. EKS cluster
  3. helm charts