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

Add ability to support multiple ALBs #13

Merged
merged 2 commits into from
Aug 4, 2020

Conversation

mohsen0
Copy link
Contributor

@mohsen0 mohsen0 commented Jul 30, 2020

Description

The change adds the ability to add multiple ALBs to a single WAF setup.

main.tf Outdated
@@ -81,14 +81,23 @@ resource "aws_wafv2_web_acl" "main" {
# WAFv2 web acl association with ALB
#####
resource "aws_wafv2_web_acl_association" "main" {
count = var.enabled && var.create_alb_association ? 1 : 0
count = var.enabled && var.create_alb_association && var.alb_arn != "" ? 1 : 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change we are getting an error:

Error: Invalid count argument

  on ../../main.tf line 84, in resource "aws_wafv2_web_acl_association" "main":
  84:   count = var.enabled && var.create_alb_association && var.alb_arn != "" ? 1 : 0

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.

This is a common thing with count unfortunately. This would only work if you provide a specific string. When you reference a module it will fail. You can replicate that behaviour by running core example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be alright now, sorry for the delay

main.tf Outdated

resource_arn = var.alb_arn
web_acl_arn = aws_wafv2_web_acl.main[0].arn

depends_on = [aws_wafv2_web_acl.main]
}

resource "aws_wafv2_web_acl_association" "alb_list" {
count = var.enabled && var.create_alb_association ? length(var.alb_arn_list) : 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps in this count we won't need var.create_alb_association and/or it should be replaced by length(var.alb_arn_list) > 0 something to test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the initial issue and decided to keep create_alb_association, hope you don't mind

@marcincuber marcincuber merged commit 17e5455 into umotif-public:master Aug 4, 2020
@mohsen0 mohsen0 deleted the support_alb_list branch August 4, 2020 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants