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

[Bug]: 'Invalid address to set' when using an ECS task as target of an EventBridge pipe #32586

Closed
gregopenit opened this issue Jul 19, 2023 · 5 comments
Labels
bug Addresses a defect in current functionality. service/pipes Issues and PRs that pertain to the pipes service.

Comments

@gregopenit
Copy link

gregopenit commented Jul 19, 2023

Terraform Core Version

1.5.3

AWS Provider Version

5.8.0

Affected Resource(s)

aws_pipes_pipe

Expected Behavior

Creation of a pipe with an SQS source and a ECS task destination is expected without error.

Actual Behavior

The pipe is correctly created but terraform provider returns an error "Invalid address to set" which looks like related to the block definition cloudwatch_logs_parameters which is not configured.

Relevant Error/Panic Output Snippet

aws_pipes_pipe.test: Still creating... [10s elapsed]
╷
│ Error: setting target_parameters: Invalid address to set: []string{"target_parameters", "0", "cloudwatch_logs_parameters", "0", "task_definition_arn"}
│ 
│   with aws_pipes_pipe.test,
│   on test.tf line 1, in resource "aws_pipes_pipe" "test":
│    1: resource "aws_pipes_pipe" "test" {
│

Terraform Configuration Files

resource "aws_pipes_pipe" "test" {
  name = "test-sqs-trigger"

  role_arn = aws_iam_role.test.arn
  source   = aws_sqs_queue.test.arn
  target   = aws_ecs_cluster.test.arn

  target_parameters {
    ecs_task_parameters {
      task_definition_arn     = aws_ecs_task_definition.test.arn
      enable_ecs_managed_tags = true
      launch_type             = "FARGATE"
      task_count              = 1
      propagate_tags          = "TASK_DEFINITION"
      network_configuration {
        aws_vpc_configuration {
          subnets          = data.aws_subnets.private.ids
          assign_public_ip = "ENABLED"
          security_groups  = [aws_security_group.test.id]
        }
      }
    }
  }
}

resource "aws_iam_role" "test" {
  name                 = "test-sqs-trigger"

  assume_role_policy = data.aws_iam_policy_document.test.json
}

data "aws_iam_policy_document" "test" {
  statement {
    actions = ["sts:AssumeRole"]

    principals {
      type        = "Service"
      identifiers = ["events.amazonaws.com", "pipes.amazonaws.com"]
    }
  }
}

resource "aws_iam_role_policy" "test" {
  name = "test-sqs-trigger"
  role = aws_iam_role.test.id

  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = [
          "ecs:RunTask"
        ]
        Effect = "Allow"
        Resource = [
          "arn:aws:ecs:eu-west-1:${data.aws_caller_identity.current.account_id}:task-definition/*:*",
          "arn:aws:ecs:eu-west-1:${data.aws_caller_identity.current.account_id}:task-definition/*"
        ]
      },
      {
        Action = [
          "iam:PassRole"
        ]
        Effect   = "Allow"
        Resource = "*"
      },
      {
        Action = [
          "sqs:ReceiveMessage",
          "sqs:DeleteMessage",
          "sqs:GetQueueAttributes"
        ]
        Effect = "Allow"
        Resource = [
          "arn:aws:sqs:eu-west-1:${data.aws_caller_identity.current.account_id}:*"
        ]
      }
    ]
  })
}

data "aws_vpc" "main" {}

data "aws_subnets" "private" {
  filter {
    name   = "vpc-id"
    values = [data.aws_vpc.main.id]
  }
  tags = {
    Attributes = "private"
  }
}

resource "aws_ecs_cluster" "test" {
  name = "test-sqs-trigger"
}

resource "aws_security_group" "test" {
  name        = "test-sqs-trigger"
  description = "Security Group for ECS Cluster"
  vpc_id      = data.aws_vpc.main.id
}

resource "aws_security_group_rule" "test-rule1" {
  type              = "ingress"
  description       = "Allow all inbound traffic"
  from_port         = 0
  to_port           = 0
  protocol          = "-1"
  security_group_id = aws_security_group.test.id
  cidr_blocks       = ["0.0.0.0/0"]
}

resource "aws_security_group_rule" "test-rule2" {
  type              = "egress"
  description       = "Allow all outbound traffic"
  from_port         = 0
  to_port           = 0
  protocol          = "-1"
  security_group_id = aws_security_group.test.id
  cidr_blocks       = ["0.0.0.0/0"]
}

resource "aws_ecs_task_definition" "test" {
  family                   = "test-sqs-trigger"
  cpu                      = 256
  memory                   = 512
  requires_compatibilities = ["FARGATE"]
  network_mode             = "awsvpc"

  container_definitions = jsonencode([
    {
      name      = "sleep"
      image     = "busybox"
      cpu       = 10
      command   = ["sleep", "300"]
      memory    = 10
      essential = true
      portMappings = [
        {
          protocol      = "tcp"
          containerPort = 8000
        }
      ]
    }
  ])
}

resource "aws_sqs_queue" "test" {
  name                       = "test-sqs-trigger"
  visibility_timeout_seconds = 3600
}

Steps to Reproduce

1/ Apply the terraform code
2/ Confirm the Eventbridge Pipe is correctly created
3/ Notice the terraform error

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@gregopenit gregopenit added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Jul 19, 2023
@github-actions github-actions bot added service/ecs Issues and PRs that pertain to the ecs service. service/iam Issues and PRs that pertain to the iam service. service/pipes Issues and PRs that pertain to the pipes service. service/sqs Issues and PRs that pertain to the sqs service. service/vpc Issues and PRs that pertain to the vpc service. labels Jul 19, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@ewbankkit ewbankkit removed service/iam Issues and PRs that pertain to the iam service. service/ecs Issues and PRs that pertain to the ecs service. service/sqs Issues and PRs that pertain to the sqs service. needs-triage Waiting for first response or review from a maintainer. service/vpc Issues and PRs that pertain to the vpc service. labels Jul 19, 2023
@ewbankkit
Copy link
Contributor

Relates #31607.

@ewbankkit
Copy link
Contributor

@gregopenit Thanks for raising this issue 👏.
It has been fixed via #32432, part of Terraform AWS Provider v5.9.0, which will be released later this week.

@gregopenit
Copy link
Author

Awesome ! Sorry I missed this MR, I only looked at the issues.
Thank you for your reply and the good news !

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/pipes Issues and PRs that pertain to the pipes service.
Projects
None yet
Development

No branches or pull requests

2 participants