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

"subnet_mapping": only one of subnet_mapping,subnets can be specified, but subnet_mapping,subnets were specified. #340

Closed
1 task done
andyli opened this issue Jan 8, 2024 · 2 comments · Fixed by #341

Comments

@andyli
Copy link
Contributor

andyli commented Jan 8, 2024

Description

AWS provider since v5.31.0, validates that exactly one of either subnets or subnet_mapping is configured.

Currently, the terraform-aws-alb module uses [] as the default of subnets. It means module users who want to use subnet_mapping have to set subnets to null in order to avoid triggering validation error:

"subnet_mapping": only one of `subnet_mapping,subnets` can be specified, but `subnet_mapping,subnets` were specified.
  • ✋ I have searched the open/closed issues and my issue is not listed.

Versions

  • Module version [Required]:
    9.4.0
  • Terraform version:
    v1.5.7
  • Provider version(s):
    provider registry.terraform.io/hashicorp/aws v5.31.0

Reproduction Code [Required]

terraform {
  required_version = "~> 1.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "= 5.31.0"
    }
  }
}

data "aws_availability_zones" "zones" {}

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "5.4.0"

  name = "alb-test"
  cidr = "10.0.0.0/16"

  azs             = data.aws_availability_zones.zones.names
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]

  enable_nat_gateway = true
  single_nat_gateway = true
}

resource "aws_eip" "lb" {
  for_each = toset(data.aws_availability_zones.zones.names)

  domain = "vpc"
  tags = {
    Name = "alb-test-${each.key}"
  }
}

module "aws-load-balancer" {
  source  = "terraform-aws-modules/alb/aws"
  version = "9.4.0"

  name = "alb-test"

  load_balancer_type               = "network"
  enable_cross_zone_load_balancing = true
  vpc_id                           = module.vpc.vpc_id

  subnet_mapping = [
    for i, az in data.aws_availability_zones.zones.names:
    {
      subnet_id     = module.vpc.public_subnets[i]
      allocation_id = aws_eip.lb[az].id
    }
  ]

  enable_deletion_protection = false
}

Expected behavior

terraform apply successfully creates the load balancer.

Actual behavior

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Invalid combination of arguments
│ 
│   with module.aws-load-balancer.aws_lb.this[0],
│   on .terraform/modules/aws-load-balancer/main.tf line 12, in resource "aws_lb" "this":
│   12: resource "aws_lb" "this" {
│ 
│ "subnet_mapping": only one of `subnet_mapping,subnets` can be specified, but `subnet_mapping,subnets` were specified.
╵
╷
│ Error: Invalid combination of arguments
│ 
│   with module.aws-load-balancer.aws_lb.this[0],
│   on .terraform/modules/aws-load-balancer/main.tf line 65, in resource "aws_lb" "this":
│   65:   subnets                    = var.subnets
│ 
│ "subnets": only one of `subnet_mapping,subnets` can be specified, but `subnet_mapping,subnets` were specified.

Additional context

A workaround is to add subnets = null when using the module. Alternatively, use AWS provider < 5.31 (with terraform-aws-alb <= 9.2.0, because the later versions depends on AWS provider >= 5.31).

@antonbabenko
Copy link
Member

This issue has been resolved in version 9.4.1 🎉

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 Feb 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants