-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Closes #3004: adds support for modifying Beanstalk tags #3513
Changes from 1 commit
13b7b88
652531c
6c194ca
5659931
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,10 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource { | |
MigrateState: resourceAwsElasticBeanstalkEnvironmentMigrateState, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
|
@@ -313,11 +317,28 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i | |
envId := d.Id() | ||
|
||
var hasChange bool | ||
var hasTagChange bool | ||
|
||
updateOpts := elasticbeanstalk.UpdateEnvironmentInput{ | ||
EnvironmentId: aws.String(envId), | ||
} | ||
|
||
updateTags := elasticbeanstalk.UpdateTagsForResourceInput{ | ||
ResourceArn: aws.String(d.Get("arn").(string)), | ||
} | ||
|
||
if d.HasChange("tags") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move all the tag update logic inside this conditional here? We do not need to make this more complicated by spreading the logic everywhere like the other update call (which needs to build up arguments). |
||
hasTagChange = true | ||
o, n := d.GetChange("tags") | ||
oldTags := tagsFromMapBeanstalk(o.(map[string]interface{})) | ||
newTags := tagsFromMapBeanstalk(n.(map[string]interface{})) | ||
|
||
tagsToAdd, tagNamesToRemove := diffTagsBeanstalk(oldTags, newTags) | ||
|
||
updateTags.TagsToAdd = tagsToAdd | ||
updateTags.TagsToRemove = tagNamesToRemove | ||
} | ||
|
||
if d.HasChange("description") { | ||
hasChange = true | ||
updateOpts.Description = aws.String(d.Get("description").(string)) | ||
|
@@ -452,6 +473,51 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i | |
} | ||
} | ||
|
||
if hasTagChange { | ||
// Get the current time to filter getBeanstalkEnvironmentErrors messages | ||
t := time.Now() | ||
log.Printf("[DEBUG] Elastic Beanstalk Environment update tags: %s", updateTags) | ||
_, err := conn.UpdateTagsForResource(&updateTags) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
waitForReadyTimeOut, err := time.ParseDuration(d.Get("wait_for_ready_timeout").(string)) | ||
if err != nil { | ||
return err | ||
} | ||
pollInterval, err := time.ParseDuration(d.Get("poll_interval").(string)) | ||
if err != nil { | ||
pollInterval = 0 | ||
log.Printf("[WARN] Error parsing poll_interval, using default backoff") | ||
} | ||
|
||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{"Launching", "Updating"}, | ||
Target: []string{"Ready"}, | ||
Refresh: environmentStateRefreshFunc(conn, d.Id(), t), | ||
Timeout: waitForReadyTimeOut, | ||
Delay: 10 * time.Second, | ||
PollInterval: pollInterval, | ||
MinTimeout: 3 * time.Second, | ||
} | ||
|
||
_, err = stateConf.WaitForState() | ||
if err != nil { | ||
return fmt.Errorf( | ||
"Error waiting for Elastic Beanstalk Environment (%s) to become ready: %s", | ||
d.Id(), err) | ||
} | ||
|
||
envErrors, err := getBeanstalkEnvironmentErrors(conn, d.Id(), t) | ||
if err != nil { | ||
return err | ||
} | ||
if envErrors != nil { | ||
return envErrors | ||
} | ||
} | ||
|
||
return resourceAwsElasticBeanstalkEnvironmentRead(d, meta) | ||
} | ||
|
||
|
@@ -496,6 +562,10 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int | |
return err | ||
} | ||
|
||
if err := d.Set("arn", env.EnvironmentArn); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Unfortunately the code around it does not follow the convention, but for simple d.Set("arn", env.EnvironmentArn) |
||
return err | ||
} | ||
|
||
if err := d.Set("name", env.EnvironmentName); err != nil { | ||
return err | ||
} | ||
|
@@ -564,6 +634,18 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int | |
return err | ||
} | ||
|
||
tags, err := conn.ListTagsForResource(&elasticbeanstalk.ListTagsForResourceInput{ | ||
ResourceArn: aws.String(d.Get("arn").(string)), | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := d.Set("tags", tagsToMapBeanstalk(tags.ResourceTags)); err != nil { | ||
return err | ||
} | ||
|
||
return resourceAwsElasticBeanstalkEnvironmentSettingsRead(d, meta) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should ensure this new attribute has an associated test of some sort in
TestAccAWSBeanstalkEnv_basic
: