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

Provider functions are not supported? #110

Open
uluzox opened this issue Dec 19, 2024 · 1 comment
Open

Provider functions are not supported? #110

uluzox opened this issue Dec 19, 2024 · 1 comment

Comments

@uluzox
Copy link

uluzox commented Dec 19, 2024

Consider

test.tf

variable "lastname" {
  type = string
 default = "bär"
}

variable "firstname" {
  type    = string
  default = "föo"
}

terraform {
  required_providers {
    corefunc = {
      source  = "northwood-labs/corefunc"
      version = "1.5.1"
    }
  }
}

locals {
  username = provider::corefunc::str_iterative_replace(
    lower("${var.firstname}.${var.lastname}"),
    [
      { old = "ä", new = "ae" },
      { old = "ö", new = "oe" },
      { old = "ü", new = "ue" },
      { old = "ß", new = "ss" },
    ],
  )
}

output "out" {
  value = local.username
}

parse-hcl.js

const { parse } = require('@cdktf/hcl2json');
const fs = require('fs').promises;

const hclFilePath = 'test.tf';

(async () => {
  try {
    // Read the HCL content from the file
    const hcl = await fs.readFile(hclFilePath, 'utf-8');

    // Parse the HCL content
    const json = await parse(hclFilePath, hcl);

    // Output the parsed JSON
    console.log(JSON.stringify(json, null, 2));
  } catch (err) {
    console.error('Error:', err.message);
  }
})();
docker run -it --rm -v $PWD:/tmp -w /tmp --entrypoint bash node:20.17 -c "npm install @cdktf/hcl2json; node parse-hcl.js"
Error: parse config: [test.tf:22,22-23: Missing newline after argument; An argument definition must end with a newline.]

However, a terraform plan works fine. And the usage of provider::corefunc::str_iterative_replace is as describe here.

docker run -it --rm -v $PWD:/tmp -w /tmp hashicorp/terraform:1.10 init 
docker run -it --rm -v $PWD:/tmp -w /tmp hashicorp/terraform:1.10 plan 

Changes to Outputs:
  + out = "foeo.baer"

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
@tmccombs
Copy link
Owner

I think this should be fixed in v0.6.5

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