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

Only reject tags for standard EIPs on EC2 Classic #18909

Merged
merged 8 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/18909.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_eip: Tags are created for EIPs which default to vpc domain
```
12 changes: 6 additions & 6 deletions aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error {
Domain: aws.String(domainOpt),
}

if domainOpt == ec2.DomainTypeVpc {
if v := d.Get("tags").(map[string]interface{}); len(v) > 0 {
supportedPlatforms := meta.(*AWSClient).supportedplatforms
if domainOpt != ec2.DomainTypeVpc && len(supportedPlatforms) > 0 && hasEc2Classic(supportedPlatforms) {
return fmt.Errorf("tags cannot be set for a standard-domain EIP - must be a VPC-domain EIP")
}
allocOpts.TagSpecifications = ec2TagSpecificationsFromMap(d.Get("tags").(map[string]interface{}), ec2.ResourceTypeElasticIp)
}

Expand Down Expand Up @@ -183,10 +187,6 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error {

log.Printf("[INFO] EIP ID: %s (domain: %v)", d.Id(), *allocResp.Domain)

if v := d.Get("tags").(map[string]interface{}); len(v) > 0 && d.Get("domain").(string) == ec2.DomainTypeStandard {
return fmt.Errorf("tags can not be set for an EIP in EC2 Classic")
}

return resourceAwsEipUpdate(d, meta)
}

Expand Down Expand Up @@ -400,7 +400,7 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {

if d.HasChange("tags") && !d.IsNewResource() {
if d.Get("domain").(string) == ec2.DomainTypeStandard {
return fmt.Errorf("tags can not be set for an EIP in EC2 Classic")
return fmt.Errorf("tags cannot be set for a standard-domain EIP - must be a VPC-domain EIP")
}
o, n := d.GetChange("tags")
if err := keyvaluetags.Ec2UpdateTags(ec2conn, d.Id(), o, n); err != nil {
Expand Down
16 changes: 8 additions & 8 deletions aws/resource_aws_eip_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccAWSEIPAssociation_instance(t *testing.T) {
{
Config: testAccAWSEIPAssociationConfig_instance(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists("aws_eip.test", &a),
testAccCheckAWSEIPExists("aws_eip.test", false, &a),
testAccCheckAWSEIPAssociationExists(resourceName, &a),
),
},
Expand All @@ -50,7 +50,7 @@ func TestAccAWSEIPAssociation_networkInterface(t *testing.T) {
{
Config: testAccAWSEIPAssociationConfig_networkInterface,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists("aws_eip.test", &a),
testAccCheckAWSEIPExists("aws_eip.test", false, &a),
testAccCheckAWSEIPAssociationExists(resourceName, &a),
),
},
Expand All @@ -76,11 +76,11 @@ func TestAccAWSEIPAssociation_basic(t *testing.T) {
{
Config: testAccAWSEIPAssociationConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists("aws_eip.test.0", &a),
testAccCheckAWSEIPExists("aws_eip.test.0", false, &a),
testAccCheckAWSEIPAssociationExists("aws_eip_association.by_allocation_id", &a),
testAccCheckAWSEIPExists("aws_eip.test.1", &a),
testAccCheckAWSEIPExists("aws_eip.test.1", false, &a),
testAccCheckAWSEIPAssociationExists("aws_eip_association.by_public_ip", &a),
testAccCheckAWSEIPExists("aws_eip.test.2", &a),
testAccCheckAWSEIPExists("aws_eip.test.2", false, &a),
testAccCheckAWSEIPAssociationExists("aws_eip_association.to_eni", &a),
),
},
Expand All @@ -106,7 +106,7 @@ func TestAccAWSEIPAssociation_ec2Classic(t *testing.T) {
{
Config: testAccAWSEIPAssociationConfig_ec2Classic(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPEc2ClassicExists("aws_eip.test", &a),
testAccCheckAWSEIPExists("aws_eip.test", true, &a),
testAccCheckAWSEIPAssociationEc2ClassicExists(resourceName, &a),
resource.TestCheckResourceAttrSet(resourceName, "public_ip"),
resource.TestCheckResourceAttr(resourceName, "allocation_id", ""),
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestAccAWSEIPAssociation_spotInstance(t *testing.T) {
{
Config: testAccAWSEIPAssociationConfig_spotInstance(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists("aws_eip.test", &a),
testAccCheckAWSEIPExists("aws_eip.test", false, &a),
testAccCheckAWSEIPAssociationExists(resourceName, &a),
resource.TestCheckResourceAttrSet(resourceName, "allocation_id"),
resource.TestCheckResourceAttrSet(resourceName, "instance_id"),
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestAccAWSEIPAssociation_disappears(t *testing.T) {
{
Config: testAccAWSEIPAssociationConfigDisappears(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists("aws_eip.test", &a),
testAccCheckAWSEIPExists("aws_eip.test", false, &a),
testAccCheckAWSEIPAssociationExists(resourceName, &a),
testAccCheckResourceDisappears(testAccProvider, resourceAwsEipAssociation(), resourceName),
),
Expand Down
Loading