Skip to content

cdktf: Found an encoded list token string in a scalar string context #3832

Open
@benkeil

Description

@benkeil

Expected Behavior

It should render the ids into the json.

Actual Behavior

We try to start an ECS task with a step function state machine with the following definition.

.withDefinition(
  """
  {
    "Comment": "${env.stage}.${env.service}.${config.name}.step-function state machine",
    "StartAt": "List Tasks",
    "States": {
      "Start Task": {
        "Resource": "arn:aws:states:::ecs:runTask.sync",
        "Parameters": {
          "LaunchType": "FARGATE",
          "Cluster": "$clusterArn",
          "TaskDefinition": "${task.taskDefinitionArn}",
          "PropagateTags": "TASK_DEFINITION",
          "NetworkConfiguration": {
            "AwsvpcConfiguration": {
              "Subnets": ${subnets.ids},
              "SecurityGroups": [
                "${task.securityGroupIdOutput}"
              ],
              "AssignPublicIp": "DISABLED"
            }
          }
        },
        "Retry": [
          {
            "ErrorEquals": [
              "States.ALL"
            ],
            "IntervalSeconds": 60,
            "MaxAttempts": 3,
            "BackoffRate": 2.0,
            "JitterStrategy": "FULL"
          }
        ],
        "End": true,
        "Type": "Task"
      },
      "Skip task": {
        "Type": "Succeed"
      },
      "List Tasks": {
        "Resource": "arn:aws:states:::aws-sdk:ecs:listTasks",
        "Parameters": {
          "Cluster": "$clusterArn",
          "DesiredStatus": "RUNNING",
          "Family": "${task.taskDefinitionArn}"
        },
        "Next": "Check for already running task",
        "Type": "Task"
      },
      "Check for already running task": {
        "Choices": [
          {
            "Not": {
              "Variable": "${'$'}.TaskArns[0]",
              "IsPresent": true
            },
            "Next": "Start Task"
          }
        ],
        "Default": "Skip task",
        "Type": "Choice"
      }
    }
  }
"""
    .trimIndent()

Our problem is the line "Subnets": ${subnets.ids}, wich lead to the error Found an encoded list token string in a scalar string context. subnets is of type DataAwsSubnets.

It sounds for me like a bug, because we don'y try yo access a single element and we also don't care about the length of the ids property. I already tried to wrap it into Token.asList which does not help.

Steps to Reproduce

Minimal code example that should point out the problem:

val subnets = DataAwsSubnets.Builder.create(this, "subnets").build()

SfnStateMachine.Builder.create(this, "SfnStateMachine")
    .name("example")
    .roleArn("arn:aws:iam::123456789012:role/foobar")
    .definition(
        """
        {
          "Comment": "A Hello World example of the Amazon States Language using Pass states",
          "StartAt": "HelloWorld",
          "States": {
            "HelloWorld": {
              "Type": "Pass",
              "Result": "Hello, World!",
              "Parameters": {
                "subnets": "${subnets.ids}"
              },
              "End": true
            }
          }
        }
        """
            .trimIndent())
    .build()

Versions

cdktf debug returns External Error: Could not determine cdktf version. Please make sure you are in a directory containing a cdktf project and have all dependencies installed.

language: java
cdktf-cli: 0.20.11

libs.versions.tom:

cdktf = { module = "com.hashicorp:cdktf", version = "0.20.11" }
cdktf-provider-aws = { module = "com.hashicorp:cdktf-provider-aws", version = "19.53.0" }
constructs = { module = "software.constructs:constructs", version = "10.4.2" }

Providers

No response

Gist

No response

Possible Solutions

No response

Workarounds

No response

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnewUn-triaged issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions