Skip to content

Commit

Permalink
provider/aws: Update the ignoring of AWS specific tags (#14321)
Browse files Browse the repository at this point in the history
We were too greedy with the AWS specific tags ignore function - we
basically were ignoring anything starting with `aws` rather than just
using `aws:`

Fixes: #14308
Fixes: #14247
  • Loading branch information
stack72 authored May 9, 2017
1 parent dddfcef commit 67bbad1
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 44 deletions.
2 changes: 1 addition & 1 deletion builtin/providers/aws/autoscaling_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func setToMapByKey(s *schema.Set, key string) map[string]interface{} {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredAutoscaling(t *autoscaling.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/s3_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func getTagSetS3(s3conn *s3.S3, bucket string) ([]*s3.Tag, error) {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredS3(t *s3.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
26 changes: 0 additions & 26 deletions builtin/providers/aws/s3_tags_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package aws

import (
"fmt"
"reflect"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestDiffTagsS3(t *testing.T) {
Expand Down Expand Up @@ -78,26 +75,3 @@ func TestIgnoringTagsS3(t *testing.T) {
}
}
}

// testAccCheckTags can be used to check the tags on a resource.
func testAccCheckTagsS3(
ts *[]*s3.Tag, key string, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
m := tagsToMapS3(*ts)
v, ok := m[key]
if value != "" && !ok {
return fmt.Errorf("Missing tag: %s", key)
} else if value == "" && ok {
return fmt.Errorf("Extra tag: %s", key)
}
if value == "" {
return nil
}

if v != value {
return fmt.Errorf("%s: bad value: %s", key, v)
}

return nil
}
}
4 changes: 2 additions & 2 deletions builtin/providers/aws/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func tagsFromMapELBv2(m map[string]interface{}) []*elbv2.Tag {
// tagIgnored compares a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnored(t *ec2.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand All @@ -295,7 +295,7 @@ func tagIgnored(t *ec2.Tag) bool {

// and for ELBv2 as well
func tagIgnoredELBv2(t *elbv2.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsBeanstalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func tagsToMapBeanstalk(ts []*elasticbeanstalk.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredBeanstalk(t *elasticbeanstalk.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsCloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func tagsToMapCloudtrail(ts []*cloudtrail.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredCloudtrail(t *cloudtrail.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsCodeBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func tagsToMapCodeBuild(ts []*codebuild.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredCodeBuild(t *codebuild.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsEC.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func tagsToMapEC(ts []*elasticache.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredEC(t *elasticache.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsEFS.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func tagsToMapEFS(ts []*efs.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredEFS(t *efs.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsELB.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func tagsToMapELB(ts []*elb.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredELB(t *elb.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsGeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func tagsToMapGeneric(ts map[string]*string) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredGeneric(k string) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, k)
if r, _ := regexp.MatchString(v, k); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsInspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func tagsToMapInspector(ts []*inspector.ResourceGroupTag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredInspector(t *inspector.ResourceGroupTag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsKMS.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func tagsToMapKMS(ts []*kms.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredKMS(t *kms.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.TagKey)
if r, _ := regexp.MatchString(v, *t.TagKey); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsRDS.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func saveTagsRDS(conn *rds.RDS, d *schema.ResourceData, arn string) error {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredRDS(t *rds.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tagsRedshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func tagsToMapRedshift(ts []*redshift.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredRedshift(t *redshift.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tags_elasticsearchservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func tagsToMapElasticsearchService(ts []*elasticsearch.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredElasticsearchService(t *elasticsearch.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tags_kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func tagsToMapKinesis(ts []*kinesis.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredKinesis(t *kinesis.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/tags_route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func tagsToMapR53(ts []*route53.Tag) map[string]string {
// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredRoute53(t *route53.Tag) bool {
filter := []string{"^aws:*"}
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
Expand Down

0 comments on commit 67bbad1

Please sign in to comment.