This repository was archived by the owner on Dec 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 499
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
cdktf: HCL Lifecycle Objects not Found in Typescript #3931
Copy link
Copy link
Open
Labels
Description
Expected Behavior
When running CDKTF init from a Terraform Project Template in HCL, the generated CDKTF Typescript does not recognize Terraform Lifecycle ignore_changes field.
Actual Behavior
Generated CDKTF App properly handles Terraform Lifecycle fields.
Steps to Reproduce
- Create a Terraform Project with resources that uses Lifecycle feature. Sample Test Case:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "6.14.1"
}
}
}
provider "aws" {
}
resource "aws_instance" "example" {
ami = "resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64"
instance_type = "t3.micro"
tags = {
Name = "HelloWorld"
}
lifecycle {
ignore_changes = [ tags ]
}
}- Initialize CDKTF from Terraform Project template
cdktf init --template=typescript \
--from-terraform-project=../terraform \
--local \
--providers=aws- Observe generated
main.tsfile for invalid lifecycle.
Versions
cdktf debug
language: typescript
cdktf-cli: 0.21.0
node: v22.17.1
cdktf: 0.21.0
constructs: 10.4.2
jsii: null
terraform: 1.13.0
arch: x64
os: darwin 24.6.0
providers
aws@6.14.1 (LOCAL)
terraform provider version: 6.14.1
@cdktf/provider-aws (PREBUILT)
terraform provider version: 6.14.1
prebuilt provider version: 21.11.1
cdktf version: ^0.21.0Providers
┌───────────────┬──────────────────┬─────────┬────────────┬─────────────────────┬─────────────────┐
│ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │
├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────┼─────────────────┤
│ aws │ 6.14.1 │ │ 6.14.1 │ │ │
├───────────────┼──────────────────┼─────────┼────────────┼─────────────────────┼─────────────────┤
│ aws │ 6.14.1 │ ^0.21.0 │ │ @cdktf/provider-aws │ 21.11.1 │
└───────────────┴──────────────────┴─────────┴────────────┴─────────────────────┴─────────────────┘```Gist
No response
Possible Solutions
From Terraform code converted to Typescript, create Lifecycle fields as String Arrays. The values are recognized, needs conversion to be string values.
Workarounds
Based on the CDKTF Lifecycle Resource defined, it expects an string array.
export interface TerraformResourceLifecycle {
readonly createBeforeDestroy?: boolean;
readonly preventDestroy?: boolean;
readonly ignoreChanges?: string[] | "all";
readonly replaceTriggeredBy?: Array<ITerraformDependable | string>;
readonly precondition?: Precondition[];
readonly postcondition?: Postcondition[];
}Whereas, the CDKTF init from Template does not create an String array. It creates the following:
lifecycle: {
ignoreChanges: [ tags ],
},I changed it to be an String and it worked, after change:
lifecycle: {
ignoreChanges: [ "tags" ],
},Anything Else?
No response
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
HackedRico and ahuseby