github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/aws/tagsBeanstalk.go (about)

     1  package aws
     2  
     3  import (
     4  	"github.com/aws/aws-sdk-go/aws"
     5  	"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
     6  )
     7  
     8  // diffTags takes our tags locally and the ones remotely and returns
     9  // the set of tags that must be created, and the set of tags that must
    10  // be destroyed.
    11  func diffTagsBeanstalk(oldTags, newTags []*elasticbeanstalk.Tag) ([]*elasticbeanstalk.Tag, []*elasticbeanstalk.Tag) {
    12  	// First, we're creating everything we have
    13  	create := make(map[string]interface{})
    14  	for _, t := range newTags {
    15  		create[*t.Key] = *t.Value
    16  	}
    17  
    18  	// Build the list of what to remove
    19  	var remove []*elasticbeanstalk.Tag
    20  	for _, t := range oldTags {
    21  		old, ok := create[*t.Key]
    22  		if !ok || old != *t.Value {
    23  			// Delete it!
    24  			remove = append(remove, t)
    25  		}
    26  	}
    27  
    28  	return tagsFromMapBeanstalk(create), remove
    29  }
    30  
    31  // tagsFromMap returns the tags for the given map of data.
    32  func tagsFromMapBeanstalk(m map[string]interface{}) []*elasticbeanstalk.Tag {
    33  	var result []*elasticbeanstalk.Tag
    34  	for k, v := range m {
    35  		result = append(result, &elasticbeanstalk.Tag{
    36  			Key:   aws.String(k),
    37  			Value: aws.String(v.(string)),
    38  		})
    39  	}
    40  
    41  	return result
    42  }
    43  
    44  // tagsToMap turns the list of tags into a map.
    45  func tagsToMapBeanstalk(ts []*elasticbeanstalk.Tag) map[string]string {
    46  	result := make(map[string]string)
    47  	for _, t := range ts {
    48  		result[*t.Key] = *t.Value
    49  	}
    50  
    51  	return result
    52  }