Hi,
I have following situation:
- We use 1 Git repository (github.com:git_org/modules_repo.git) as a source of all Terraform infrastructure, locally-developed and downloaded Terraform modules.
- These modules are in repository’s subfolder.
- Several modules are used within single .tf file. All modules refer to the same repository’s address and version as source.
Example:
module "kops_data_iam" {
source = "git@github.com:git_org/modules_repo.git//components/terraform/.modules/kops-data-iam?ref=main"
cluster_name = var.cluster_name
}
module "kops_data_network" {
source = "git@github.com:git_org/modules_repo.git//components/terraform/.modules/kops-data-network?ref=main"
cluster_name = var.cluster_name
}
we’re getting error message:
Initializing modules…
Downloading git::GitHub - cloudposse/terraform-aws-kms-key at tags/0.4.0 for kms_key…
- kms_key in .terraform/modules/kms_key
- Downloading git::GitHub - cloudposse/terraform-null-label at tags/0.16.0 for kms_key.label…
- kms_key.label in .terraform/modules/kms_key.label
- Downloading git::GitHub - cloudposse/terraform-terraform-label at tags/0.4.0 for kms_key_alias…
- kms_key_alias in .terraform/modules/kms_key_alias
- Downloading git@github.com:git_org/modules_repo.git?ref=main for kops_data_iam…
- kops_data_iam in .terraform/modules/kops_data_iam/components/terraform/.modules/kops-data-iam
- Downloading git@github.com:git_org/modules_repo.git?ref=main for kops_data_network…
- Downloading git::GitHub - cloudposse/terraform-aws-rds at tags/0.19.0 for rds…
- rds in .terraform/modules/rds
Error: Failed to download module
Could not download module “kops_data_network” (kops-data.tf:15) source code
from “git@github.com:git_org/modules_repo.git?ref=main”: subdir
“components/terraform/.modules/kops-data-network” not found
I’ve tried:
- Using different source formats described in Module Sources - Terraform by HashiCorp - for Github, generic Git, git via ssh & https etc.
- Removing cached .terraform files, running terraform init and downloading all modules again.
- Replaced ‘source’ for kops_data_iam with local path - “…/modules/kops-data-iam”. After that it was able to download kops_data_network successfully.
After “3” I replaced kops_data_iam back with reference to remote Git repository and it stopped working again. Error message was the same. It looks like using the same Git repository as source for different modules is not supported.
Could someone confirm it’s expected behavior and whether it’s supported scenario, please?