diff --git a/.changelog/17612.txt b/.changelog/17612.txt new file mode 100644 index 00000000000..20ff384d344 --- /dev/null +++ b/.changelog/17612.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_eip: Tags are set on create +``` diff --git a/aws/resource_aws_eip.go b/aws/resource_aws_eip.go index 3b20e3cab1e..4c8290e9fa4 100644 --- a/aws/resource_aws_eip.go +++ b/aws/resource_aws_eip.go @@ -145,6 +145,10 @@ func resourceAwsEipCreate(d *schema.ResourceData, meta interface{}) error { Domain: aws.String(domainOpt), } + if domainOpt == ec2.DomainTypeVpc { + allocOpts.TagSpecifications = ec2TagSpecificationsFromMap(d.Get("tags").(map[string]interface{}), ec2.ResourceTypeElasticIp) + } + if v, ok := d.GetOk("public_ipv4_pool"); ok { allocOpts.PublicIpv4Pool = aws.String(v.(string)) } @@ -179,13 +183,8 @@ 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 { - if d.Get("domain").(string) == ec2.DomainTypeStandard { - return fmt.Errorf("tags can not be set for an EIP in EC2 Classic") - } - if err := keyvaluetags.Ec2CreateTags(ec2conn, d.Id(), v); err != nil { - return fmt.Errorf("error adding tags: %s", err) - } + 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)