Skip to content

Inconsistent behaviour of dependsOn if set via initial resource config vs. via resource.dependsOn #2334

Open
@mihok

Description

@mihok

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

Description

Currently tokens are forced into strings, and dependsOn or addOverride resolves these down to templated strings, which are not allowed. Where a block of code such as this:

    const account = new ServiceAccount(scope, `${name}-account`, {
      accountId: name,
      description: "Generated by Terraform",
    });

    const key = new ServiceAccountKey(scope, `${name}-key`, {
      serviceAccountId: account.id,
      publicKeyType: "TYPE_RAW_PUBLIC_KEY",
    });

    key.dependsOn = [ account.id ];

Which results in the following error from terraform:

│ Error: Invalid expression
│ 
│   on cdk.tf.json line 102, in resource.google_service_account_key.logging-robot-key.depends_on:
│  102:           "${google_service_account.logging-robot-account.id}",
│ 
│ A single static variable reference is required: only attribute access and
│ indexing with constant keys. No calculations, function calls, template
│ expressions, etc are allowed here.

There needs to be a simple way for people to reference the object without templated strings.

Ideally, this might be as simple as having some kind of toUntemplatedString (ugly, not set on the name of the function/property)

So the above code would look something along the lines of:

    const account = new ServiceAccount(scope, `${name}-account`, {
      accountId: name,
      description: "Generated by Terraform",
    });

    const key = new ServiceAccountKey(scope, `${name}-key`, {
      serviceAccountId: account.id,
      publicKeyType: "TYPE_RAW_PUBLIC_KEY",
    });

    key.dependsOn = [ account.idRaw ];

Which result in a cdk.tf.json:

 
 "depends_on": [
   "google_service_account.logging-robot-account.id"
 ]

Happy to do some of the implementation if it helps!

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestpriority/important-longtermMedium priority, to be worked on within the following 1-2 business quarters.size/mediumestimated < 1 weekux/configuration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions