Skip to content

Commit

Permalink
Merge pull request #17612 from rick-masters/f-aws_eip-tagoncreate
Browse files Browse the repository at this point in the history
Include tags in options for creating vpc EIPs.
  • Loading branch information
gdavison authored Apr 6, 2021
2 parents 5a568a1 + a07af4c commit 102e6da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/17612.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_eip: Tags are set on create
```
13 changes: 6 additions & 7 deletions aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 102e6da

Please sign in to comment.