sjm
sjm

Reputation: 465

Creating AWS_ALB From Terraform

I am trying to create a simple AWS_ALB via terraform, I have created a separate VPC with public and private subnets but the ALB creating is giving me invalidSubnet error

resource "aws_alb" "test" {
  name            = "test-alb-tf"
  internal        = false
  security_groups = ["sg-0385b126e18d3ca67"]
  subnets         = ["192.168.11.0/24"]
}

Public subnets are created as below

        {
            "MapPublicIpOnLaunch": true,
            "AvailabilityZoneId": "use1-az2",
            "Tags": [
                {
                    "Value": "staging",
                    "Key": "Environment"
                },
                {
                    "Value": "secure-public-us-east-1a",
                    "Key": "Name"
                },
                {
                    "Value": "true",
                    "Key": "Terraform"
                }
            ],
            "AvailableIpAddressCount": 250,
            "DefaultForAz": false,
            "SubnetArn": "arn:aws:ec2:us-east-1:041840987519:subnet/subnet-03757baf0df052c07",
            "Ipv6CidrBlockAssociationSet": [],
            "VpcId": "vpc-00689d5ff034a0c99",
            "State": "available",
            "AvailabilityZone": "us-east-1a",
            "SubnetId": "subnet-03757baf0df052c07",
            "OwnerId": "041840987519",
            "CidrBlock": "192.168.11.0/24",
            "AssignIpv6AddressOnCreation": false
        },

This is what terraform plan show

  # aws_alb.test will be created
  + resource "aws_alb" "test" {
      + arn                        = (known after apply)
      + arn_suffix                 = (known after apply)
      + dns_name                   = (known after apply)
      + enable_deletion_protection = false
      + enable_http2               = true
      + id                         = (known after apply)
      + idle_timeout               = 60
      + internal                   = false
      + ip_address_type            = (known after apply)
      + load_balancer_type         = "application"
      + name                       = "test-alb-tf"
      + security_groups            = [
          + "sg-0385b126e18d3ca67",
        ]
      + subnets                    = [
          + "192.168.11.0/24",
        ]
      + vpc_id                     = (known after apply)
      + zone_id                    = (known after apply)

      + subnet_mapping {
          + allocation_id = (known after apply)
          + subnet_id     = (known after apply)
        }
    }

and this is the error that I am getting

Error: Error creating application Load Balancer: InvalidSubnet: The subnet ID '192.168.11.0/24' is not valid
    status code: 400, request id: 5521ae30-dc0b-4f4c-ae89-47eb729126c7

Anyone got an idea as to what i am missing

Upvotes: 0

Views: 2627

Answers (1)

BMW
BMW

Reputation: 45333

So the error clearly shows the problem.

The subnet ID '192.168.11.0/24' is not valid

Did you login the aws console and check what subnet you want to assign to this ALB? it has the id as subnet-xxxxxxxx

Upvotes: 2

Related Questions