Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add resource tags for appmesh mesh resource #8111

Conversation

teraken0509
Copy link
Contributor

@teraken0509 teraken0509 commented Mar 28, 2019

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Reference #8101

Changes proposed in this pull request:

  • Add tag resource for appmesh service
  • Add tags attribute for aws_appmesh_mesh resource

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/Mesh'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSAppmesh/Mesh -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/Mesh
=== RUN   TestAccAWSAppmesh/Mesh/tags
=== RUN   TestAccAWSAppmesh/Mesh/basic
--- PASS: TestAccAWSAppmesh (108.16s)
    --- PASS: TestAccAWSAppmesh/Mesh (108.16s)
        --- PASS: TestAccAWSAppmesh/Mesh/tags (77.71s)
        --- PASS: TestAccAWSAppmesh/Mesh/basic (30.45s)
PASS
ok  	github.com/terraform-providers/tmp-terraform-provider-aws/aws	108.233s

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Mar 28, 2019
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/appmesh Issues and PRs that pertain to the appmesh service. labels Mar 28, 2019
@teraken0509 teraken0509 force-pushed the feature/add-resource-tags-for-appmesh-mesh-resource branch from 44bc6ef to 15c199a Compare April 12, 2019 04:40
@teraken0509
Copy link
Contributor Author

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/Mesh'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSAppmesh/Mesh -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/Mesh
=== RUN   TestAccAWSAppmesh/Mesh/basic
=== RUN   TestAccAWSAppmesh/Mesh/egressFilter
=== RUN   TestAccAWSAppmesh/Mesh/tags
--- PASS: TestAccAWSAppmesh (179.38s)
    --- PASS: TestAccAWSAppmesh/Mesh (179.38s)
        --- PASS: TestAccAWSAppmesh/Mesh/basic (37.31s)
        --- PASS: TestAccAWSAppmesh/Mesh/egressFilter (67.56s)
        --- PASS: TestAccAWSAppmesh/Mesh/tags (74.51s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	179.459s

@ewbankkit
Copy link
Contributor

Can we get a review of this please?
tagsAppmesh.go is required for adding resource tags to the other App Mesh resources listed in #8101.

@@ -127,6 +130,15 @@ func resourceAwsAppmeshMeshRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("error setting spec: %s", err)
}

if err := saveTagsAppmesh(conn, d, aws.StringValue(resp.Mesh.Metadata.Arn)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the preferred style for error handling is

err = saveTagsAppmesh(conn, d, aws.StringValue(resp.Mesh.Metadata.Arn))
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
    log.Printf("[WARN] App Mesh service mesh (%s) not found, removing from state", d.Id())
    d.SetId("")
    return nil
}
if err != nil {
    return fmt.Errorf("error saving tags: %s", err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -147,6 +159,15 @@ func resourceAwsAppmeshMeshUpdate(d *schema.ResourceData, meta interface{}) erro
}
}

if err := setTagsAppmesh(conn, d, d.Get("arn").(string)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed too.

@teraken0509 teraken0509 force-pushed the feature/add-resource-tags-for-appmesh-mesh-resource branch from 15c199a to f1fe342 Compare April 22, 2019 04:12
@teraken0509
Copy link
Contributor Author

Re-run tests.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/Mesh'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSAppmesh/Mesh -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/Mesh
=== RUN   TestAccAWSAppmesh/Mesh/basic
=== RUN   TestAccAWSAppmesh/Mesh/egressFilter
=== RUN   TestAccAWSAppmesh/Mesh/tags
--- PASS: TestAccAWSAppmesh (185.23s)
    --- PASS: TestAccAWSAppmesh/Mesh (185.23s)
        --- PASS: TestAccAWSAppmesh/Mesh/basic (36.70s)
        --- PASS: TestAccAWSAppmesh/Mesh/egressFilter (68.07s)
        --- PASS: TestAccAWSAppmesh/Mesh/tags (80.46s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	185.314s

@teraken0509
Copy link
Contributor Author

@ewbankkit could you review fixes?

@aeschright aeschright requested review from a team and removed request for a team June 26, 2019 16:50
@ewbankkit
Copy link
Contributor

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/Mesh'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSAppmesh/Mesh -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/Mesh
=== RUN   TestAccAWSAppmesh/Mesh/egressFilter
=== RUN   TestAccAWSAppmesh/Mesh/tags
=== RUN   TestAccAWSAppmesh/Mesh/basic
--- PASS: TestAccAWSAppmesh (115.91s)
    --- PASS: TestAccAWSAppmesh/Mesh (115.91s)
        --- PASS: TestAccAWSAppmesh/Mesh/egressFilter (44.72s)
        --- PASS: TestAccAWSAppmesh/Mesh/tags (50.00s)
        --- PASS: TestAccAWSAppmesh/Mesh/basic (21.19s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	115.996s

@@ -157,7 +180,7 @@ func resourceAwsAppmeshMeshDelete(d *schema.ResourceData, meta interface{}) erro
_, err := conn.DeleteMesh(&appmesh.DeleteMeshInput{
MeshName: aws.String(d.Id()),
})
if isAWSErr(err, "NotFoundException", "") {
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Could you also replace the hard-coded string value in resourceAwsAppmeshMeshRead()? https:/terraform-providers/terraform-provider-aws/blob/1bb0dead12829bf6c9da9e3170f52a8f24984497/aws/resource_aws_appmesh_mesh.go#L107

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

}

// Build the list of what to remove
var remove []*string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

// compare a tag against a list of strings and checks if it should
// be ignored or not
func tagIgnoredAppmesh(t *appmesh.TagRef) bool {
filter := []string{"^aws:", "^appmesh:", "Name"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to exclude Name and appmesh: here?
In my testing these tags don't seem to be added automagically and I can add manually:

$ aws --region us-west-2 appmesh tag-resource --resource-arn "arn:aws:appmesh:us-west-2:000000000000:mesh/simpleapp" --tags "key=Name,value=test"
$ aws --region us-west-2 appmesh tag-resource --resource-arn "arn:aws:appmesh:us-west-2:000000000000:mesh/simpleapp" --tags "key=appmesh:k,value=v"
$ aws --region us-west-2 appmesh list-tags-for-resource --resource-arn "arn:aws:appmesh:us-west-2:000000000000:mesh/simpleapp"
{
    "tags": [
        {
            "value": "test", 
            "key": "Name"
        }, 
        {
            "value": "v", 
            "key": "appmesh:k"
        }
    ]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I remove Name and appmesh: from ignore list

@teraken0509 teraken0509 force-pushed the feature/add-resource-tags-for-appmesh-mesh-resource branch from f1fe342 to f1de04e Compare June 27, 2019 22:38
@teraken0509 teraken0509 requested a review from a team June 27, 2019 22:38
@teraken0509
Copy link
Contributor Author

Re-run acctest.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/Mesh'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSAppmesh/Mesh -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/Mesh
=== RUN   TestAccAWSAppmesh/Mesh/basic
=== RUN   TestAccAWSAppmesh/Mesh/egressFilter
=== RUN   TestAccAWSAppmesh/Mesh/tags
--- PASS: TestAccAWSAppmesh (142.94s)
    --- PASS: TestAccAWSAppmesh/Mesh (142.94s)
        --- PASS: TestAccAWSAppmesh/Mesh/basic (27.22s)
        --- PASS: TestAccAWSAppmesh/Mesh/egressFilter (52.34s)
        --- PASS: TestAccAWSAppmesh/Mesh/tags (63.38s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	143.056s

@teraken0509 teraken0509 force-pushed the feature/add-resource-tags-for-appmesh-mesh-resource branch from f1de04e to 0aa99f7 Compare June 27, 2019 22:58
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for helping review @ewbankkit and for this implementation @kterada0509! LGTM 🚀

--- PASS: TestAccAWSAppmesh (131.28s)

@bflad bflad added this to the v2.17.0 milestone Jun 27, 2019
@bflad
Copy link
Contributor

bflad commented Jun 27, 2019

(Fixing the minor unit/linting error on merge so we can get this released today)

aws/tagsAppmesh_test.go:29:4: cannot use map[string]string literal (type map[string]string) as type []string in field value
aws/tagsAppmesh_test.go:43:4: cannot use map[string]string literal (type map[string]string) as type []string in field value
aws/tagsAppmesh_test.go:61:4: cannot use map[string]string literal (type map[string]string) as type []string in field value
aws/tagsAppmesh_test.go:76:4: cannot use map[string]string literal (type map[string]string) as type []string in field value

@bflad bflad merged commit 0aa99f7 into hashicorp:master Jun 28, 2019
bflad added a commit that referenced this pull request Jun 28, 2019
bflad added a commit that referenced this pull request Jun 28, 2019
@bflad
Copy link
Contributor

bflad commented Jun 28, 2019

This has been released in version 2.17.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Nov 3, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 3, 2019
@teraken0509 teraken0509 deleted the feature/add-resource-tags-for-appmesh-mesh-resource branch March 5, 2020 14:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/appmesh Issues and PRs that pertain to the appmesh service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants