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

cdktf convert is not working with local modules in parent directories #3008

Closed
1 task
sig-piskule opened this issue Jul 13, 2023 · 5 comments
Closed
1 task
Labels
bug Something isn't working feature/convert stale An issue or pull request that has not been updated in a very long time waiting-on-answer

Comments

@sig-piskule
Copy link

Expected Behavior

I have a very complicated project written in HCL. Although our code is still messy, I'd like to attempt to convert it all to CDKTF. The directory structure is like this:

/modules/rds/main.tf
/modules/rds/outputs.tf
/modules/rds/variables.tf
/modules/rds/versions.tf
/project/aws-project/customers/customera/certificate.tf
/project/aws-project/customers/customera/helm.tf
/project/aws-project/customers/customera/locals.tf
/project/aws-project/customers/customera/main.tf
/project/aws-project/customers/customera/variables.tf
/project/aws-project/customers/customera/versions.tf

Conceptually, a customer has a helm chart and RDS instance. We should make nearly everything a module, but we haven't yet, so the helm chart is not yet a module. I have navigated to the /project/aws-project/customers/customera/ folder, and I am trying to convert this entire (messy) structure to CDKTF.

I have created a CDKTF like this:

{
    "app": "test",
    "language": "python",
    "terraformModules": [
        {
            "name": "modules/rds",
            "source":  "../../../../modules/rds"
        }  
    ],
    "terraformProviders": ["aws","random"],
    "projectId": "1234180c-1234-1234-1234-123426cd1234"
}

My expectation is that when I run $ cat *.tf | cdktf convert from the /project/aws-project/customers/customera/ folder, that a python script is outputted to STDOUT.

Actual Behavior

Instead of getting the expected output, I instead get an error

SyntaxError: Unexpected token, expected "from" (2:18)
  1 | /* @babel/template */;
> 2 | import * as  from "./.gen/modules/rds/"

that has been baffling to fix. It seems as if the interpret is trying to generate code like import * as rds from "./.gen/modules/rds/", but that for some reason the line is blank.

I have verified that my module seems to be downloaded to the correct location:

$ ls ./.gen/modules/rds/
__init__.py	_jsii		py.typed

See The Full Stacktrace Error Below:

SyntaxError: Unexpected token, expected "from" (2:18)
  1 | /* @babel/template */;
> 2 | import * as  from "./.gen/modules/rds/"
    |                  ^
    at instantiate (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:63:32)
    at constructor (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:358:12)
    at PlaceholdersParserMixin.raise (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:3255:19)
    at PlaceholdersParserMixin.unexpected (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:3285:16)
    at PlaceholdersParserMixin.expectContextual (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:3604:12)
    at PlaceholdersParserMixin.parseImportSpecifiersAndAfter (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:14122:10)
    at PlaceholdersParserMixin.parseImport (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:14114:17)
    at PlaceholdersParserMixin.parseImport (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:10332:36)
    at PlaceholdersParserMixin.parseStatementContent (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:12706:27)
    at PlaceholdersParserMixin.parseStatementLike (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:12584:17)
Collecting Debug Information...
/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
        throw ex;
        ^

SyntaxError: Unexpected token, expected "from" (2:18)
  1 | /* @babel/template */;
> 2 | import * as  from "./.gen/modules/rds/"
    |                  ^
    at instantiate (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:63:32)
    at constructor (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:358:12)
    at PlaceholdersParserMixin.raise (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:3255:19)
    at PlaceholdersParserMixin.unexpected (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:3285:16)
    at PlaceholdersParserMixin.expectContextual (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:3604:12)
    at PlaceholdersParserMixin.parseImportSpecifiersAndAfter (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:14122:10)
    at PlaceholdersParserMixin.parseImport (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:14114:17)
    at PlaceholdersParserMixin.parseImport (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:10332:36)
    at PlaceholdersParserMixin.parseStatementContent (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:12706:27)
    at PlaceholdersParserMixin.parseStatementLike (/opt/homebrew/lib/node_modules/cdktf-cli/node_modules/@babel/parser/lib/index.js:12584:17) {
  language: 'python',
  __type: 'Internal'
}

Steps to Reproduce

  1. Create a module in the /modules/rds directory.
  2. Create a HCL configuration the /projects/subdir/subdir/ directory. Make sure it uses /modules/rds in the HCL configuration.
  3. Create a cdktf.json which specified the ../../../modules/rds directory.
  4. Run cdktf get
  5. Run cat *.tf | cdktf convert

Versions

$ cdktf --version
0.17.1
$ node --version
v18.16.1
$ terraform --version
Terraform v1.5.3
on darwin_arm64

Providers

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.1.0"
      configuration_aliases = [ aws.rds ]
    }
    kubernetes = {
      source  = "registry.terraform.io/hashicorp/kubernetes"
      version = "~> 2.21.0"
    }
    helm = {
      source  = "registry.terraform.io/hashicorp/helm"
      version = "~> 2.1"
    }
    kubectl = {
      source  = "gavinbunney/kubectl"
      version = "~> 1.13.0"
    }
    random = {
      source  = "registry.terraform.io/hashicorp/random"
      version = "~> 3.1"
    }
  }

Gist

No response

Possible Solutions

This could be a simple misconfiguration on my end. I have investigated if there are any open-source projects doing something similar to what I am trying to do, and I have not found any examples. As a result, I wonder if anyone has tried to do what I am doing.

This search yeilds no results for similar effort:

Workarounds

No, still investigating a possible fix, and I will update this issue if I find one.

Anything Else?

The cdktf.json I believe needs to have the name modules/rds instead of just rds. Otherwise, cdktf get will not download the rds module into the correct location. This leads me to believe that the documentation needs to be updated to handle my use-case, and possibly needs more specification.

References

The following document suggests what I am trying to do should be possible, but I due to the error I am receiving and incorrect download location, I am unsure of what I am doing wrong.

For local modules, please use the object format to ensure that CDKTF can properly name the generated classes.

{
  // ...
  "terraformModules": [
    {
      "name": "myLocalModule",
      "source": "../my-modules/local-module"
    }
  ]
}

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@sig-piskule sig-piskule added bug Something isn't working new Un-triaged issue labels Jul 13, 2023
@DanielMSchmidt
Copy link
Contributor

I think we don't support a / in the name of a module, could you try a flat name that creates no hierarchy?

@github-actions
Copy link
Contributor

Hi there! 👋 We haven't heard from you in 15 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.

@github-actions github-actions bot added the stale An issue or pull request that has not been updated in a very long time label Aug 20, 2023
@mutahhir mutahhir removed the new Un-triaged issue label Sep 14, 2023
@github-actions github-actions bot removed stale An issue or pull request that has not been updated in a very long time waiting-on-answer labels Sep 15, 2023
@github-actions
Copy link
Contributor

Hi there! 👋 We haven't heard from you in 15 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.

@github-actions github-actions bot added the stale An issue or pull request that has not been updated in a very long time label Oct 28, 2023
Copy link
Contributor

I'm closing this issue because we haven't heard back in 45 days. ⌛️ If you still need help, feel free to comment or reopen the issue!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working feature/convert stale An issue or pull request that has not been updated in a very long time waiting-on-answer
Projects
None yet
Development

No branches or pull requests

5 participants