Hi there!
I use typescript for developing script.
I have problem with reading value from remote state.
As we can read from tokens after command cdktf synth string “#{TOKEN[TOKEN.9]}” will resolve the token to ${module.<module id>.public_subnets}
.
I try to create some resources.
Code:
for (let index = 0; index < (blue.getList(“asg_ids”)).length; index++) {
new AutoscalingAttachment(this,
"blue_to_nlb",{
autoscalingGroupName: blue.getList("asg_ids")[index],
albTargetGroupArn: nlb.getString('tg_arn_stage_c')
});
}
where: blue(list of asg_ids) and nlb data from remote state
After command cdktf synth I`ve got cdk.tf.json file like this
“resource”: {
“aws_autoscaling_attachment”: {
“a911trafficcontroltypescript_a911bluetonlb_6CDD2D28”: {
“alb_target_group_arn”:
“${data.terraform_remote_state.stagea_9F839440.outputs.tg_stage_c}”,
“autoscaling_group_name”: “#{Token[TOKEN.1]}”,
As we can see Token is not replaced and after command terraform plan I got a new plan like this:
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
aws_autoscaling_attachment.stagea_9F839440 must be replaced
-/+ resource “aws_autoscaling_attachment”
“stagea_9F839440” {
alb_target_group_arn = “arn:xxxxx”
~ autoscaling_group_name = “stage-a-blue” -> “#{Token[TOKEN.1]}” # forces replacement
~ id = “00000001” -> (known after apply)
}
Plan: 1 to add, 0 to change, 1 to destroy.
but I’ve read an existing remote state and I expect that it sould be sync and I’ll get notification that it syncs No changes
How to read a value from array by using Tokens?
Is it possible?