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

aws_alb_listener_rule doesn't import "action" if "condition" is query-string #354

Open
edutu85 opened this issue Jan 6, 2024 · 5 comments

Comments

@edutu85
Copy link

edutu85 commented Jan 6, 2024

I am trying to import the exisiting aws infrastructure in terraform and I'm getting different results depending on what tool I use.
I am fairly new to terraform.

  • using former2 to import ALB listerner rule if condition is query-string:

resource "aws_lb_listener_rule" "ElasticLoadBalancingV2ListenerRule" {
priority = "1"
listener_arn = "arn:aws:elasticloadbalancing:us-west-1:12345678:listener/app/test/1f0678e51e01c7d0a1b2c3d4/4d3c2b1a"
condition {
field = "query-string"
}
}

  • terraformer will import as bellow:

resource "aws_lb_listener_rule" "tfer--arn-ElasticLoadBalancingV2ListenerRule" {
action {
order = "1"
target_group_arn = "arn:aws:elasticloadbalancing:us-west-1:12345678:targetgroup/testtargetgroup/aa1bb2cc3dd4"
type = "forward"
}

condition {
query_string {
key = "mystring"
value = "02"
}

query_string {
  key   = "mystring"
  value = "03"
}

}
}

Am I missing something?
Thank you

iann0036 added a commit that referenced this issue Jan 7, 2024
@iann0036
Copy link
Owner

iann0036 commented Jan 7, 2024

Hi @edutu85,

Thanks for raising!

It looks like there was a missing Terraform field mapping for this. I've gone ahead and added that for you now. Give it another go and let me know if you still have issues.

@edutu85
Copy link
Author

edutu85 commented Jan 7, 2024

@iann0036 - thank you for looking at this.
The action shows up now; hoever, the condition is incomplete - it's missing the name and the value of the string the elb is performing the query on:

  • former2 generates only
condition {
field = "query-string"
}

  • terraformer generates:
 condition {
query_string {
key = "mystring"
value = "02"
}

The syntax looks to be different between the two tools. When I tun terraform validate against the terrafrom code generated with former2, I get this error:

  condition {
      field = "host-header"
│ An argument named "field" is not expected here.

I think "field = "query-string" " will generate same error (but have not verified it yet).

Thank you

iann0036 added a commit that referenced this issue Jan 16, 2024
@iann0036
Copy link
Owner

Hi @edutu85,

Thanks for that breakdown. It looks like the multi-variable stuff got added after resource creation a while back.

I've made those changes now, but unsure if it'll format correctly (blocks vs. array of map) in Terraform. Let me know how you go.

@edutu85
Copy link
Author

edutu85 commented Jan 22, 2024

hi @iann0036 - thank you for looking over this.
It took me a while to get the terraform code working.
Here's the output from former2

condition {
        query_string {
            values = [
                {
                    key = "foo"
                    value = "02"
                },
                {
                    key = "foo"
                    value = "03"
                }
            ]
        }
}

while the terraform code I was able to run and generate the rules I needed is:

condition {
    query_string {
      key   = "foo"
      value = "02"
    }
    query_string {
      key   = "foo"
      value = "03"
    }

  }

I hope this is useful.

iann0036 added a commit that referenced this issue Jan 23, 2024
@iann0036
Copy link
Owner

Hey @edutu85,

I've made that change for you. That is strange, the docs do seem to say there's a values block in the middle. Maybe bad docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants