hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.84k stars 9.19k forks source link

[Bug]: IPAM - The request can only contain PubliclyAdvertisable if the AddressFamily is IPv6 and PublicIpSource is byoip. #39967

Closed kverstr closed 1 week ago

kverstr commented 2 weeks ago

Terraform Core Version

1.9.8

AWS Provider Version

5.72.x

Affected Resource(s)

aws_vpc_ipam_pool

Expected Behavior

with following parameters: public_ip_source = amazon ip_scope_type = public address_family = ipv6 aws_service = ec2

"publicly_advertisable" parameter should not be passed in this case

I expect to be able to create an IPAM pool that allocates an AWS generated CIDR block.

Actual Behavior

publicly_advertisable parameter is passed, doesn't matter which value it has. you get the error 'The request can only contain PubliclyAdvertisable if the AddressFamily is IPv6 and PublicIpSource is byoip.'

seems like the wrong checks are done here: https://github.com/hashicorp/terraform-provider-aws/blob/ce1c31d9c90de12d93279b1bcaa6da9e2ae5b592/internal/service/ec2/ipam_pool.go#L207

a check should be done on PublicIpSource instead of IpamScopeType?

Relevant Error/Panic Output Snippet

Error: creating IPAM Pool: operation error EC2: CreateIpamPool, https response error StatusCode: 400, RequestID: blabla, api error InvalidParameterCombination: The request can only contain PubliclyAdvertisable if the AddressFamily is IPv6 and PublicIpSource is byoip.

Terraform Configuration Files

terraform {
  required_version = "~> 1.0"
  required_providers {
    aws = {
      source                = "hashicorp/aws"
      #version             = "5.56.1" #this works
     version             = "~> 5.0"  #doesnt work 
    }
  }

module "ipv6_aws_eu_west_1" {
  source  = "aws-ia/ipam/aws"
  version = "~> 2.0"

  top_name                  = "AWS IPv6 pool eu-west-1"
  top_netmask_length        = "45"
  address_family            = "ipv6"
  ipam_scope_type           = "public"
  top_aws_service           = "ec2"
  top_publicly_advertisable = null # or true or false; doesn't matter what value
  top_public_ip_source      = "amazon"
  top_locale                = "eu-west-1"

  pool_configurations = {
    eu-west-1 = {
      name                  = "AWS IPv6 pool eu-west-1"
      description           = "Pool for ipv6 eu-west-1"
      netmask_length        = "45"
      locale                = "eu-west-1"
      aws_service           = "ec2"
      public_ip_source      = "amazon"

      sub_pools = {
        lab-public = {
          name                  = "AWS public IPv6 pool eu-west-1 lab"
          netmask_length        = "49"
          aws_service           = "ec2"
          ram_share_principals  = []
          public_ip_source      = "amazon"
        }
        lab-private = {
          name                  = "AWS private IPv6 pool eu-west-1 lab"
          netmask_length        = "49"
          aws_service           = "ec2"
          ram_share_principals  = []
          public_ip_source      = "amazon"
        }
        nprd-public = {
          name                  = "AWS public IPv6 pool eu-west-1 nprd"
          netmask_length        = "47"
          aws_service           = "ec2"
          ram_share_principals  = []
          public_ip_source      = "amazon"
        }
        nprd-private = {
          name                  = "AWS private IPv6 pool eu-west-1 nprd"
          netmask_length        = "47"
          aws_service           = "ec2"
          ram_share_principals  = []
          public_ip_source      = "amazon"
        }
        prod-public = {
          name                  = "AWS public IPv6 pool eu-west-1 prod"
          netmask_length        = "48"
          aws_service           = "ec2"
          ram_share_principals  = []
          public_ip_source      = "amazon"
        }
        prod-private = {
          name                  = "AWS private IPv6 pool eu-west-1 prod"
          netmask_length        = "48"
          aws_service           = "ec2"
          ram_share_principals  = []
          public_ip_source      = "amazon"
        }
      }
    }
  }
}

Steps to Reproduce

run this code with the AWS provider on ~> 5.0 and with provider version 5.56.1 for example (I used this version because it was in my local .terraform providers and I knew at some point my configuration worked)

Debug Output

failing request: it has PubliclyAdvertisable passed.

{
    "eventVersion": "1.10",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": ,
        "accountId": "",
        "accessKeyId": "",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "",
                "arn": "",
                "accountId": "",
                "userName": ""
            },
            "attributes": {
                "creationDate": "2024-10-31T12:51:43Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2024-10-31T12:51:44Z",
    "eventSource": "ec2.amazonaws.com",
    "eventName": "CreateIpamPool",
    "awsRegion": "eu-west-1",
    "sourceIPAddress": "",
    "userAgent": "APN/1.0 HashiCorp/1.0 Terraform/1.9.8 (+https://www.terraform.io) terraform-provider-aws/5.72.1 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go-v2/1.32.2 os/macos lang/go#1.23.2 md/GOOS#darwin md/GOARCH#arm64 api/ec2#1.182.0",
    "errorCode": "Client.InvalidParameterCombination",
    "errorMessage": "The request can only contain PubliclyAdvertisable if the AddressFamily is IPv6 and PublicIpSource is byoip.",
    "requestParameters": {
        "CreateIpamPoolRequest": {
            "AwsService": "ec2",
            "IpamScopeId": "ipam-scope-12345",
            "Locale": "eu-west-1",
            "PublicIpSource": "amazon",
            "AddressFamily": "ipv6",
            "ClientToken": "",
            "TagSpecification": {
                "ResourceType": "ipam-pool",
                "tag": 1,
                "Tag": {
                    "Value": "AWS IPv6 pool eu-west-1",
                    "tag": 1,
                    "Key": "Name"
                }
            },
            "PubliclyAdvertisable": true
        }
    },
    "responseElements": null,
    "requestID": "",
    "eventID": "",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "",
    "eventCategory": "Management",
    "tlsDetails": {
        "tlsVersion": "TLSv1.3",
        "cipherSuite": "TLS_AES_128_GCM_SHA256",
        "clientProvidedHostHeader": "ec2.eu-west-1.amazonaws.com"
    }
}

working request (provider 5.56.1): PubliclyAdvertisable is not passed, however in my TF configuration I didn't change anything

{
    "eventVersion": "1.10",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "",
        "arn": "",
        "accountId": "",
        "accessKeyId": "",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "",
                "arn": "",
                "accountId": "",
                "userName": ""
            },
            "attributes": {
                "creationDate": "2024-10-31T12:54:22Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2024-10-31T12:54:23Z",
    "eventSource": "ec2.amazonaws.com",
    "eventName": "CreateIpamPool",
    "awsRegion": "eu-west-1",
    "sourceIPAddress": "",
    "userAgent": "APN/1.0 HashiCorp/1.0 Terraform/1.9.8 (+https://www.terraform.io) terraform-provider-aws/5.56.1 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go-v2/1.30.0 os/macos lang/go#1.22.4 md/GOOS#darwin md/GOARCH#arm64 api/ec2#1.166.0",
    "requestParameters": {
        "CreateIpamPoolRequest": {
            "AwsService": "ec2",
            "IpamScopeId": "ipam-scope-1234",
            "Locale": "eu-west-1",
            "PublicIpSource": "amazon",
            "AddressFamily": "ipv6",
            "ClientToken": "",
            "TagSpecification": {
                "ResourceType": "ipam-pool",
                "tag": 1,
                "Tag": {
                    "Value": "AWS IPv6 pool eu-west-1",
                    "tag": 1,
                    "Key": "Name"
                }
            }
        }
    },
    "responseElements": {
        "CreateIpamPoolResponse": {
            "xmlns": "http://ec2.amazonaws.com/doc/2016-11-15/",
            "requestId": "",
            "ipamPool": {
                "autoImport": false,
                "ipamPoolArn": "",
                "publicIpSource": "amazon",
                "ipamScopeType": "public",
                "locale": "eu-west-1",
                "ownerId": "",
                "ipamRegion": "eu-west-1",
                "tagSet": {
                    "item": {
                        "value": "AWS IPv6 pool eu-west-1",
                        "key": "Name"
                    }
                },
                "ipamScopeArn": "",
                "ipamPoolId": "",
                "poolDepth": 1,
                "state": "create-in-progress",
                "ipamArn": "",
                "addressFamily": "ipv6",
                "awsService": "ec2"
            }
        }
    },
    "requestID": "",
    "eventID": "",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "",
    "eventCategory": "Management",
    "tlsDetails": {
        "tlsVersion": "TLSv1.3",
        "cipherSuite": "TLS_AES_128_GCM_SHA256",
        "clientProvidedHostHeader": "ec2.eu-west-1.amazonaws.com"
    }
}

Panic Output

No response

Important Factoids

you probably need to decrease the CIDR sizes in order to run this, I had my quote increased by AWS. (default limit is /52)

References

Caused by #39600

Would you like to implement a fix?

None

github-actions[bot] commented 2 weeks ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 2 weeks ago

Relates #39600

kverstr commented 2 weeks ago

Yeah, I guess that is the change that broke this. image

YakDriver commented 1 week ago

I have repro'd this and working on a fix.

github-actions[bot] commented 1 week ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

github-actions[bot] commented 4 days ago

This functionality has been released in v5.75.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!