Esempio n. 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)
	}
}
Esempio n. 2
0
func deleteTags(ctx context.Context, svc elasticsearchservice.ElasticsearchService, resourceIds []*string) {
	if len(ctx.RmTags) <= 0 {
		return
	}

	for _, arn := range resourceIds {
		_, err := svc.RemoveTags(&elasticsearchservice.RemoveTagsInput{
			ARN:     arn,
			TagKeys: rmtagArgsToESTags(ctx.RmTags),
		})

		kingpin.FatalIfError(err, "Could not delete tags for elastic search resources %s", resourceIds)
	}
}
Esempio n. 3
0
func printTags(ctx context.Context, svc elasticsearchservice.ElasticsearchService, resourceIds []*string) {
	if ctx.Verbose {
		for _, arn := range resourceIds {
			ctx.PrintVerbose(fmt.Sprintf("    Processing domain %s", *arn))
			resp, _ := svc.ListTags(&elasticsearchservice.ListTagsInput{
				ARN: arn,
			})

			// Well, this will throw an error if there are no tags instead of just returning an empty list...ugh
			// kingpin.FatalIfError(err, "Could not retrieve tags for elastic search domain %s", arn)

			for _, tag := range resp.TagList {
				ctx.PrintVerbose(fmt.Sprintf("      %s=%s", *tag.Key, *tag.Value))
			}
		}
	}
}
Esempio n. 4
0
func getArns(svc *elasticsearchservice.ElasticsearchService) []*string {
	nresp, err := svc.ListDomainNames(&elasticsearchservice.ListDomainNamesInput{})

	domainNames := make([]*string, 0)
	for _, dn := range nresp.DomainNames {
		domainNames = append(domainNames, dn.DomainName)
	}

	resp, err := svc.DescribeElasticsearchDomains(&elasticsearchservice.DescribeElasticsearchDomainsInput{
		DomainNames: domainNames,
	})

	kingpin.FatalIfError(err, "Could not retrieve elastic search resources")

	arns := make([]*string, 0)
	for _, esd := range resp.DomainStatusList {
		arns = append(arns, esd.ARN)
	}

	return arns
}
// 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
}