Skip to content

for_each in pipeline step messes up the value #561

Closed
@luisffc

Description

I've noticed a weird behaviour on pipeline step when iterating. It seems the each.value always return the last element.
The example bellow shows a pipeline running 3 times, the first to run is able to create the resource named pipeling-test-2 and the other two runs fails trying to create a resource with the same name.
It was expected to create the resources pipeling-test-0, pipeling-test-1, and pipeling-test-2 instead.

Note that when I try the same iteration on a transform step, the names are printed correctly.

Example:

  step "transform" "resource_names" {
    value = [for i in range(param.amount) : "${param.role_name}-${i}"]
  }

  output "resource_names" {
    value = step.transform.resource_names.value
  }

  // // Debugging
  // step "transform" "iterating_over_resource_names" {
  //   for_each = [for name in step.transform.resource_names.value : name]
  //   value = each.value
  // }

  // // Debugging
  // output "iterating_over_resource_names" {
  //   value = step.transform.iterating_over_resource_names
  // }

  step "pipeline" "create_iam_role" {
    for_each = [for name in step.transform.resource_names.value : name]
    pipeline = aws.pipeline.create_iam_role
    args = {
      cred      = param.aws_cred
      role_name = each.value
      assume_role_policy_document = param.assume_role_policy_document
    }
  }

Gives me the following error:

$ fpr create_iam_roles --arg amount=3
[flowpipe] Execution ID: exec_cmesjr4i016p9ohpprq0
[create_iam_roles] Starting pipeline
[create_iam_roles.resource_names] Starting transform
[create_iam_roles.resource_names] Complete 1ms
[create_iam_roles.create_iam_role[0]] Starting pipeline
[create_iam_roles.create_iam_role[1]] Starting pipeline
[create_iam_roles.create_iam_role[2]] Starting pipeline
[create_iam_role] Starting pipeline
[create_iam_role] Starting pipeline
[create_iam_role] Starting pipeline
[create_iam_role.create_iam_role] Starting container
[create_iam_role.create_iam_role] Starting container
[create_iam_role.create_iam_role] Starting container
[create_iam_role.create_iam_role] Execution Error: 
An error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.

[create_iam_role] Output errors = [
  {
    "error": {
      "detail": "\nAn error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.\n",
      "instance": "fperr_cmesjski016p9ohpps3g",
      "status": 460,
      "title": "Execution Error",
      "type": "error_execution"
    },
    "pipeline": "aws.pipeline.create_iam_role",
    "pipeline_execution_id": "pexec_cmesjr4i016p9ohpprtg",
    "step": "container.create_iam_role",
    "step_execution_id": "sexec_cmesjr4i016p9ohpps20"
  }
]
[create_iam_role] Execution Error: 
An error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.

[create_iam_role] Failed 5s
[create_iam_roles.create_iam_role[0]] Execution Error: 
An error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.

[create_iam_roles.create_iam_role[0]] Failed 6s
[create_iam_role.create_iam_role] Complete 6s
[create_iam_role] Output role = {
  "Arn": "arn:aws:iam::157447638907:role/pipeling-test-2",
  "AssumeRolePolicyDocument": {
    "Statement": [
      {
        "Action": "sts:AssumeRole",
        "Effect": "Allow",
        "Principal": {
          "Service": "ec2.amazonaws.com"
        }
      }
    ],
    "Version": "2012-10-17"
  },
  "CreateDate": "2024-01-09T22:34:26+00:00",
  "Path": "/",
  "RoleId": "AROASJKE4J555JR3SLWXF",
  "RoleName": "pipeling-test-2"
}
[create_iam_role] Complete 6s
[create_iam_roles.create_iam_role[2]] Complete 6s
[create_iam_role.create_iam_role] Execution Error: 
An error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.

[create_iam_role] Output errors = [
  {
    "error": {
      "detail": "\nAn error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.\n",
      "instance": "fperr_cmesjski016p9ohpps40",
      "status": 460,
      "title": "Execution Error",
      "type": "error_execution"
    },
    "pipeline": "aws.pipeline.create_iam_role",
    "pipeline_execution_id": "pexec_cmesjr4i016p9ohpprv0",
    "step": "container.create_iam_role",
    "step_execution_id": "sexec_cmesjr4i016p9ohpps2g"
  }
]
[create_iam_role] Execution Error: 
An error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.

[create_iam_role] Failed 6s
[create_iam_roles.create_iam_role[1]] Execution Error: 
An error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.

[create_iam_roles.create_iam_role[1]] Failed 6s
[create_iam_roles] Output errors = [
  {
    "error": {
      "detail": "\nAn error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.\n",
      "instance": "fperr_cmesjski016p9ohpps3g",
      "status": 460,
      "title": "Execution Error",
      "type": "error_execution"
    },
    "pipeline": "aws.pipeline.create_iam_role",
    "pipeline_execution_id": "pexec_cmesjr4i016p9ohpprtg",
    "step": "container.create_iam_role",
    "step_execution_id": "sexec_cmesjr4i016p9ohpps20"
  },
  {
    "error": {
      "detail": "\nAn error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.\n",
      "instance": "fperr_cmesjski016p9ohpps40",
      "status": 460,
      "title": "Execution Error",
      "type": "error_execution"
    },
    "pipeline": "aws.pipeline.create_iam_role",
    "pipeline_execution_id": "pexec_cmesjr4i016p9ohpprv0",
    "step": "container.create_iam_role",
    "step_execution_id": "sexec_cmesjr4i016p9ohpps2g"
  }
]
[create_iam_roles] Execution Error: 
An error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.

[create_iam_roles] Execution Error: 
An error occurred (EntityAlreadyExists) when calling the CreateRole operation: Role with name pipeling-test-2 already exists.

[create_iam_roles] Failed with 2 errors 6s

If I comment out the pipeline step and uncomment the debugging steps, I get the following output:

$ fpr create_iam_roles --arg amount=3
[flowpipe] Execution ID: exec_cmeskaci016pb3idil60
[create_iam_roles] Starting pipeline
[create_iam_roles.resource_names] Starting transform
[create_iam_roles.resource_names] Complete 2ms
[create_iam_roles.iterating_over_resource_names[0]] Starting transform
[create_iam_roles.iterating_over_resource_names[0]] Complete 1ms
[create_iam_roles.iterating_over_resource_names[1]] Starting transform
[create_iam_roles.iterating_over_resource_names[1]] Complete 3ms
[create_iam_roles.iterating_over_resource_names[2]] Starting transform
[create_iam_roles.iterating_over_resource_names[2]] Complete 1ms
[create_iam_roles] Output iterating_over_resource_names = {
  "0": {
    "value": "pipeling-test-0"
  },
  "1": {
    "value": "pipeling-test-1"
  },
  "2": {
    "value": "pipeling-test-2"
  }
}
[create_iam_roles] Output resource_names = [
  "pipeling-test-0",
  "pipeling-test-1",
  "pipeling-test-2"
]
[create_iam_roles] Complete 23ms exec_cmeskaci016pb3idil60

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

blockerbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions