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

chore: Update HCL Interoperability docs to include HCL synthesis #3462

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions website/docs/cdktf/concepts/hcl-interoperability.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ description: >-

# HCL Interoperability

Terraform requires infrastructure configuration files written in either [HashiCorp Configuration Language (HCL)](/terraform/language/syntax/configuration) or JSON syntax. CDK for Terraform (CDKTF) works by translating configurations defined in an imperative programming language to JSON configuration files for Terraform.
Terraform requires infrastructure configuration files written in either [HashiCorp Configuration Language (HCL)](/terraform/language/syntax/configuration) or JSON syntax. CDK for Terraform (CDKTF) works by translating configurations defined in an imperative programming language to JSON configuration files for Terraform.
Starting from version 0.20, CDKTF can also generate Terraform HCL as output by setting the `--hcl` flag when running `cdktf synth`.

CDKTF may not be the right choice for every team and project within your organization. For example, some teams may already be very familiar with Terraform and have created HCL modules, providers, etc. To provide flexibility, CDKTF applications are interoperable with Terraform projects written in HCL. Specifically:

Expand Down Expand Up @@ -200,9 +201,10 @@ func NewHclInteropStack(scope constructs.Construct, name string) cdktf.Terraform

</CodeTabs>

To use this as a Terraform module, run `cdktf synth` and copy the resulting `cdktf.out/stacks/random-pet-module/cdktf.json` file out to the module directory in your HCL project.
To use this as a Terraform module, run `cdktf synth` and copy the resulting `cdktf.out/stacks/random-pet-module/cdk.tf.json` file out to the module directory in your HCL project.
By default, `cdktf synth` generates Terraform JSON, but starting from version 0.20, CDKTF can also generate Terraform HCL output by passing the `--hcl` flag to `cdktf synth`.

After you transfer the `cdktf.json` file, you can reference the pet name module as you would any other HCL Terraform module.
After you transfer the `cdk.tf.json` (or `cdk.tf`) file, you can reference the pet name module as you would any other HCL Terraform module.

```terraform
terraform {
Expand All @@ -224,6 +226,8 @@ output "name" {
}
```



## HCL to CDKTF

Use the [`cdktf convert`](/terraform/cdktf/cli-reference/commands#convert) command to automatically translate existing HCL into a preferred CDKTF language. The [modules documentation](/terraform/cdktf/concepts/modules) shows how to use existing Terraform modules in CDK for Terraform projects.
mutahhir marked this conversation as resolved.
Show resolved Hide resolved
Loading