Example #1
0
func updateTags(ctx context.Context, svc elasticsearchservice.ElasticsearchService, resourceIds []*string) {
	if len(ctx.Tags) <= 0 {
		return
	}

	for _, arn := range resourceIds {
		_, err := svc.AddTags(&elasticsearchservice.AddTagsInput{
			ARN:     arn,
			TagList: tagArgsToESTags(ctx.Tags),
		})

		kingpin.FatalIfError(err, "Could not update tags for elastic search resources %s", resourceIds)
	}
}
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setTagsElasticsearchService(conn *elasticsearch.ElasticsearchService, d *schema.ResourceData, arn string) error {
	if d.HasChange("tags") {
		oraw, nraw := d.GetChange("tags")
		o := oraw.(map[string]interface{})
		n := nraw.(map[string]interface{})
		create, remove := diffTagsElasticsearchService(tagsFromMapElasticsearchService(o), tagsFromMapElasticsearchService(n))

		// Set tags
		if len(remove) > 0 {
			log.Printf("[DEBUG] Removing tags: %#v", remove)
			k := make([]*string, 0, len(remove))
			for _, t := range remove {
				k = append(k, t.Key)
			}
			_, err := conn.RemoveTags(&elasticsearch.RemoveTagsInput{
				ARN:     aws.String(arn),
				TagKeys: k,
			})
			if err != nil {
				return err
			}
		}
		if len(create) > 0 {
			log.Printf("[DEBUG] Creating tags: %#v", create)
			_, err := conn.AddTags(&elasticsearch.AddTagsInput{
				ARN:     aws.String(arn),
				TagList: create,
			})
			if err != nil {
				return err
			}
		}
	}

	return nil
}