provider/aws: Update the ignoring of AWS specific tags (#14321)

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
This commit is contained in:
Paul Stack 2017-05-09 20:19:33 +03:00 committed by GitHub
parent dddfcef556
commit 67bbad1cf0
18 changed files with 18 additions and 44 deletions

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredAutoscaling(t *autoscaling.Tag) bool { func tagIgnoredAutoscaling(t *autoscaling.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredS3(t *s3.Tag) bool { func tagIgnoredS3(t *s3.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -1,14 +1,11 @@
package aws package aws
import ( import (
"fmt"
"reflect" "reflect"
"testing" "testing"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
) )
func TestDiffTagsS3(t *testing.T) { func TestDiffTagsS3(t *testing.T) {
@ -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
}
}

View File

@ -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 // tagIgnored compares a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnored(t *ec2.Tag) bool { func tagIgnored(t *ec2.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {
@ -295,7 +295,7 @@ func tagIgnored(t *ec2.Tag) bool {
// and for ELBv2 as well // and for ELBv2 as well
func tagIgnoredELBv2(t *elbv2.Tag) bool { func tagIgnoredELBv2(t *elbv2.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredBeanstalk(t *elasticbeanstalk.Tag) bool { func tagIgnoredBeanstalk(t *elasticbeanstalk.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredCloudtrail(t *cloudtrail.Tag) bool { func tagIgnoredCloudtrail(t *cloudtrail.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredCodeBuild(t *codebuild.Tag) bool { func tagIgnoredCodeBuild(t *codebuild.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredEC(t *elasticache.Tag) bool { func tagIgnoredEC(t *elasticache.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredEFS(t *efs.Tag) bool { func tagIgnoredEFS(t *efs.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredELB(t *elb.Tag) bool { func tagIgnoredELB(t *elb.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredGeneric(k string) bool { func tagIgnoredGeneric(k string) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, k) log.Printf("[DEBUG] Matching %v with %v\n", v, k)
if r, _ := regexp.MatchString(v, k); r == true { if r, _ := regexp.MatchString(v, k); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredInspector(t *inspector.ResourceGroupTag) bool { func tagIgnoredInspector(t *inspector.ResourceGroupTag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredKMS(t *kms.Tag) bool { func tagIgnoredKMS(t *kms.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.TagKey) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.TagKey)
if r, _ := regexp.MatchString(v, *t.TagKey); r == true { if r, _ := regexp.MatchString(v, *t.TagKey); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredRDS(t *rds.Tag) bool { func tagIgnoredRDS(t *rds.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredRedshift(t *redshift.Tag) bool { func tagIgnoredRedshift(t *redshift.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredElasticsearchService(t *elasticsearch.Tag) bool { func tagIgnoredElasticsearchService(t *elasticsearch.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredKinesis(t *kinesis.Tag) bool { func tagIgnoredKinesis(t *kinesis.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {

View File

@ -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 // compare a tag against a list of strings and checks if it should
// be ignored or not // be ignored or not
func tagIgnoredRoute53(t *route53.Tag) bool { func tagIgnoredRoute53(t *route53.Tag) bool {
filter := []string{"^aws:*"} filter := []string{"^aws:"}
for _, v := range filter { for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key) log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true { if r, _ := regexp.MatchString(v, *t.Key); r == true {