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

ReplaceTriggeredBy: Still not working in Golang #3546

Open
1 task
eahrend opened this issue Mar 11, 2024 · 2 comments
Open
1 task

ReplaceTriggeredBy: Still not working in Golang #3546

eahrend opened this issue Mar 11, 2024 · 2 comments
Labels
bug/has-workaround A bug with a workaround (may not be elegant) bug Something isn't working language/golang priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters.

Comments

@eahrend
Copy link

eahrend commented Mar 11, 2024

Expected Behavior

I should be able to create a replaceTriggeredBy lifecycle rule by specifying the FQN of the resource that I want to cause a replacement trigger for, like:

	triggersMap := map[string]*string{
		"databases": jsii.String(strings.Join(dbNames, ",")), // trigger on database changes
	}
	resourceId := jsii.Sprintf("cloud-sql-user-%s-%s-%s-trigger", h.ProjectName, h.Struct.Name, userName)
	userReplacementTrigger := nr.NewResource(h.Stack, resourceId, &nr.ResourceConfig{Triggers: &triggersMap})
	lifecycle := cdktf.TerraformResourceLifecycle{
		ReplaceTriggeredBy: &[]interface{}{
			userReplacementTrigger.Fqn(),
		},
	}

Actual Behavior

I get an invalid expression. The cdktf.json file shows:

    "google_sql_user": {
        ###REDACTED###
        "lifecycle": {
          "replace_triggered_by": [
            "${null_resource.cloud-sql-user-my-instance-default-user-trigger}"
          ]
        },
        ###REDACTED###
      },

Steps to Reproduce

Apply the stack with the relevant code.

Versions

Couldn't get the info from cdktf debug

npm list -g
/Users/erik/.local/lib
├── cdktf-cli@0.20.1
└── cdktf@0.20.1
go version
go version go1.21.6 darwin/arm64
terraform version
Terraform v1.7.0
on darwin_arm64
Node.js v20.11.0

Running this command fails with this error:

Error: Pre-built provider information not found
    at Bnr (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:171:2225)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async zU (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:171:1716)
    at async lde (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:171:4004)
    at async /Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:176:3945
    at async Promise.all (index 2)
    at async Kk.allProviders (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:176:3854)
    at async Object.L8r (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:551:1832)
    at async JZ.handleCommand (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cdktf.js:85:887)
    at async Object.handler (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cdktf.js:84:15344)

Providers

Running this command fails with this error:

Error: Pre-built provider information not found
    at Bnr (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:171:2225)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async zU (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:171:1716)
    at async lde (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:171:4004)
    at async /Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:176:3945
    at async Promise.all (index 2)
    at async Kk.allProviders (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:176:3854)
    at async Object.L8r (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cmds/handlers.js:551:1832)
    at async JZ.handleCommand (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cdktf.js:85:887)
    at async Object.handler (/Users/erik/.local/lib/node_modules/cdktf-cli/bundle/bin/cdktf.js:84:15344)

Gist

No response

Possible Solutions

No response

Workarounds

Workaround is to write it like this:

	lifecycle := cdktf.TerraformResourceLifecycle{
		ReplaceTriggeredBy: &[]interface{}{
			// Workaround for https://github.com/hashicorp/terraform-cdk/issues/3196
			fmt.Sprintf("%s.%s", *userReplacementTrigger.TerraformResourceType(), *userReplacementTrigger.FriendlyUniqueId()),
		},
	}

Anything Else?

No response

References

#3196
#1866 (comment)

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
@eahrend eahrend added bug Something isn't working new Un-triaged issue labels Mar 11, 2024
@TylerJGabb
Copy link

I am interested in working on this issue.

@ansgarm ansgarm added language/golang priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. bug/has-workaround A bug with a workaround (may not be elegant) and removed new Un-triaged issue labels Mar 18, 2024
@MWS-TAI
Copy link

MWS-TAI commented Mar 21, 2024

I am also experiencing this issue with Python, have tried providing just the resource variable and using .fqn as 3322 code changes suggest.

The workaround by @eahrend seems to work

lifecycle=TerraformResourceLifecycle(
    replace_triggered_by=[
        f"{self.__redshift_namespace.terraform_resource_type}.{self.__redshift_namespace.friendly_unique_id}",
    ]
)
"lifecycle": {
      "replace_triggered_by": [
          "aws_redshiftserverless_namespace.redshift__redshift_namespace"
      ]
    },

I believe the underlying issue is that the fqn property includes the hcl templating syntax as shown below in the cdktf.json when I use fqn:

lifecycle=TerraformResourceLifecycle(
    replace_triggered_by=[
        f"{self.__redshift_namespace.fqn}",
    ]
)
"lifecycle": {
      "replace_triggered_by": [
          "${aws_redshiftserverless_namespace.redshift__redshift_namespace}"
      ]
    },

I am not sure if fqn including the syntax is by design, but that seems to be the underlying issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/has-workaround A bug with a workaround (may not be elegant) bug Something isn't working language/golang priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters.
Projects
None yet
Development

No branches or pull requests

4 participants