4
votes

I'm using a local exec provisioner in terraform to run aws cli commands that get around terraform's lack of support for certain aws features. The command in question is to create a listener-rule for Application Load Balancer. Here's the call in question (numbers fuzzed):

aws elbv2 create-rule 
--listener-arn arn:aws:elasticloadbalancing:us-west-1:394416156998:listener/app/lb-name/22e3a19c3c684f8b/17032dfaae523461 
--priority 2 
--conditions Field=http-request-method,Values='GET' 
--actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-west-1:394416159845:targetgroup/target-group-name/2ff8e99a44a24219

This yields the error:

(ValidationError) when calling the CreateRule operation: 'arn:aws:elasticloadbalancing:us-west-1:394416155421:listener/app/alb-name/92e1a32c3c684f2b/64032dfaae753032' must be in ARN format

However, if you examine the example in amazon's own documentation, they use exactly the same ARN format, unless I'm missing the obvious.

Here's my terraform code:

resource "null_resource" "rule-maker" {
  provisioner "local-exec" {
    command = "aws elbv2 create-rule --listener-arn ${data.aws_arn.listener-arn.arn} --priority 2 --conditions Field=http-request-method,Values='GET' --actions Type=forward,TargetGroupArn=${aws_alb_target_group.name.arn}"
  }
}
2
Try enclosing ${data.aws_arn.listener-arn.arn} in double quotes like: "aws elbv2 create-rule --listener-arn \"${data.aws_arn.listener-arn.arn}\" --priority 2 --conditions Field=http-request-method,Values='GET' --actions Type=forward,TargetGroupArn=${aws_alb_target_group.name.arn}"progfan
Why are you shelling out to the AWS CLI here instead of using Terraform to create the ALB listener rule?ydaetskcoR

2 Answers

5
votes

Fixed this by ensuring the region was correct. The default region was different from my cluster, and caused it to throw this (misleading) ARN error.

aws configure --region CORRECT_REGION

1
votes

You can override default region using --region command line parameter or environment variable AWS_DEFAULT_REGION.

E.g.

aws elbv2 create-rule --region us-east-1  --listener-arn ...

It's especially useful if you need to run AWS CLI commands against different regions from one client machine.

Please find more details here:

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration-region