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 & Backend information is not removed in cdktf 0.20.0 --hcl output #299

Open
1 task
shinebayar-g opened this issue Jan 13, 2024 · 1 comment
Open
1 task
Labels
bug Something isn't working

Comments

@shinebayar-g
Copy link
Contributor

shinebayar-g commented Jan 13, 2024

Description

Using the following example

import { App } from 'cdktf';
import { Construct } from 'constructs';
import {
    TFModuleStack,
    TFModuleVariable,
    TFModuleOutput,
    ProviderRequirement,
} from '@cdktf/tf-module-stack';
import { Resource } from '@cdktf/provider-null/lib/resource';

class MyAwesomeModule extends TFModuleStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        new ProviderRequirement(this, 'null', '~> 2.0');
        const resource = new Resource(this, 'resource');

        new TFModuleVariable(this, 'my_var', {
            type: 'string',
            description: 'A variable',
            default: 'default',
        });

        new TFModuleOutput(this, 'my_output', {
            value: resource.id,
        });
    }
}

const app = new App();
new MyAwesomeModule(app, 'my-awesome-module');
app.synth();

cdktf synth generates

cdktf-modules
├── cdktf.out
│   ├── manifest.json
│   └── stacks
│       └── my-awesome-module
│           └── cdk.tf.json
└── main.ts

cdk.tf.json content

{
  "//": {
    "metadata": {
      "backend": "local",
      "stackName": "my-awesome-module",
      "version": "0.20.0"
    },
    "outputs": {
      "my-awesome-module": {
        "my_output": "my_output"
      }
    }
  },
  "output": {
    "my_output": [
      {
        "value": "${null_resource.resource.id}"
      }
    ]
  },
  "resource": {
    "null_resource": {
      "resource": {
        "//": {
          "metadata": {
            "path": "my-awesome-module/resource",
            "uniqueId": "resource"
          }
        }
      }
    }
  },
  "terraform": {
    "required_providers": {
      "null": {
        "version": "~> 2.0"
      }
    }
  },
  "variable": {
    "my_var": [
      {
        "default": "default",
        "description": "A variable",
        "type": "string"
      }
    ]
  }
}

cdktf synth --hcl generates

cdktf-modules
├── cdktf.out
│   ├── manifest.json
│   └── stacks
│       └── my-awesome-module
│           ├── cdk.tf
│           └── metadata.json
└── main.ts

cdk.tf content

terraform {
  required_providers {
    null = {
      version = "~> 2.0"
    }
  }
  backend "local" {
    path = "/Users/Home/cdktf-modules/terraform.my-awesome-module.tfstate"
  }


}

provider "null" {
}
resource "null_resource" "resource" {
}

variable "my_var" {
  default     = "default"
  description = "A variable"
  type        = string
}

output "my_output" {
  value = "${null_resource.resource.id}"
}

metadata.json content

{
  "//": {
    "metadata": {
      "backend": "local",
      "stackName": "my-awesome-module",
      "version": "0.20.0"
    },
    "outputs": {
      "my-awesome-module": {
        "my_output": "my_output"
      }
    }
  },
  "resource": {
    "null_resource": {
      "resource": {
        "//": {
          "metadata": {
            "path": "my-awesome-module/resource",
            "uniqueId": "resource"
          }
        }
      }
    }
  },
  "terraform": {
    "backend": {
      "local": {
        "path": "/Users/Home/cdktf-modules/terraform.my-awesome-module.tfstate"
      }
    },
    "required_providers": {
      "null": {
        "version": "~> 2.0"
      }
    }
  }
}

Versions

language: typescript
cdktf-cli: 0.20.0
cdktf: 0.20.0
node: v20.10.0
constructs: 10.3.0
terraform: v1.3.7
arch: arm64
os: darwin 23.2.0

Providers

"@cdktf/provider-null": "10.0.0",
"@cdktf/tf-module-stack": "5.0.0"

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

Is metadata.json file needed? It looks identical to the previous json version.

References

No response

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
@shinebayar-g shinebayar-g added the bug Something isn't working label Jan 13, 2024
@DanielMSchmidt
Copy link
Contributor

We don't support HCL output in this repository right now, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants