infracost: HCL parsing does not work with modules that have a `source` in a private Terraform registry
HCL parsing does not work if the Terraform code contains a module with a source in a private Terraform registry. Private git modules work ok.
Example this code:
provider "aws" {
region = "us-east-1"
skip_credentials_validation = true
skip_requesting_account_id = true
access_key = "mock_access_key"
secret_key = "mock_secret_key"
}
module "ec2_cluster" {
source = "app.terraform.io/infracost/ec2-instance/aws"
version = "~> 2.0"
name = "my-cluster"
instance_count = 5
ami = "ami-ebd02392"
instance_type = "t2.micro"
key_name = "user1"
monitoring = true
vpc_security_group_ids = ["sg-12345678"]
subnet_id = "subnet-eddcdzz4"
}
Shows this error:
Error: Error loading Terraform modules: error downloading 'file:///examples/terraform/.infracost/terraform_modules/ec2_cluster/app.terraform.io/infracost/ec2-instance/aws': source path error: stat /examples/terraform/.infracost/terraform_modules/ec2_cluster/app.terraform.io/infracost/ec2-instance/aws: no such file or directory
There’s two issues which are causing this:
- Our code assumes that the module API is always at
<host>/v1/modules
but this can be different for different registries. We should use the terraform-svchost package to discover the correct service URLs - Our code does not pass through any credentials when pulling remote registry modules.
I’ve created a work in progress branch here.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 17 (8 by maintainers)
@aliscott should we re-open this issue until gitlab support is confirmed as working by @EppO or should we create a new issue to track it? (@EppO I really appreciate your help with that)
Thanks @EppO - I’ve added a fix for the relative download paths in https://github.com/infracost/infracost/pull/1795.
Yeah you’re right, but this requires the credentials to be passed through to go-getter which we aren’t currently doing, so I went with a different approach.
in https://www.terraform.io/registry/api-docs#download-source-code-for-a-specific-module-version, docs say:
so I assume infracost needs to support both, relative and absolute.
no rush, let me know when I can try again.
That’s indeed what I’m using
I guess that depends if your repo is public or private. I would assume it supports both. I will give it a try if you need.