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

service/appmesh: update to using typelist #13337

Merged
merged 4 commits into from
May 21, 2020
Merged

service/appmesh: update to using typelist #13337

merged 4 commits into from
May 21, 2020

Conversation

anGie44
Copy link
Contributor

@anGie44 anGie44 commented May 15, 2020

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" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #9956

Release note for CHANGELOG:

service/appmesh: correct typeset usage with typelist in cases where max_items is 1

Output from acceptance testing:

--- PASS: TestAccAWSAppmesh (206.43s)
    --- PASS: TestAccAWSAppmesh/VirtualNode (206.43s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/basic (16.93s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/cloudMapServiceDiscovery (111.75s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/listenerHealthChecks (22.79s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/logging (22.79s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/tags (32.17s)

--- PASS: TestAccAWSAppmesh (54.20s)
    --- PASS: TestAccAWSAppmesh/VirtualRouter (54.20s)
        --- PASS: TestAccAWSAppmesh/VirtualRouter/tags (32.77s)
        --- PASS: TestAccAWSAppmesh/VirtualRouter/basic (21.43s)

@ghost ghost added size/XS Managed by automation to categorize the size of a PR. service/appmesh Issues and PRs that pertain to the appmesh service. labels May 15, 2020
@anGie44 anGie44 added the technical-debt Addresses areas of the codebase that need refactoring or redesign. label May 15, 2020
@anGie44 anGie44 changed the title resource/appmesh: update to using typelist service/appmesh: update to using typelist May 15, 2020
@anGie44 anGie44 linked an issue May 15, 2020 that may be closed by this pull request
28 tasks
@anGie44 anGie44 marked this pull request as ready for review May 18, 2020 20:57
@anGie44 anGie44 requested a review from a team May 18, 2020 20:57
@ewbankkit
Copy link
Contributor

Running acceptance tests:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAppmesh/VirtualNode/'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSAppmesh/VirtualNode/ -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/VirtualNode
=== RUN   TestAccAWSAppmesh/VirtualNode/listenerHealthChecks
=== RUN   TestAccAWSAppmesh/VirtualNode/logging
=== RUN   TestAccAWSAppmesh/VirtualNode/tags
=== RUN   TestAccAWSAppmesh/VirtualNode/basic
=== RUN   TestAccAWSAppmesh/VirtualNode/cloudMapServiceDiscovery
--- FAIL: TestAccAWSAppmesh (204.90s)
    --- FAIL: TestAccAWSAppmesh/VirtualNode (204.90s)
        --- FAIL: TestAccAWSAppmesh/VirtualNode/listenerHealthChecks (13.54s)
            testing.go:683: Step 0 error: errors during apply:
                
                Error: error creating App Mesh virtual node: BadRequestException: Service Discovery can't be set without a listener.
                
                  on /tmp/tf-test582579556/main.tf line 6:
                  (source code not available)
                
                
        --- FAIL: TestAccAWSAppmesh/VirtualNode/logging (13.73s)
            testing.go:683: Step 0 error: errors during apply:
                
                Error: error creating App Mesh virtual node: BadRequestException: Service Discovery can't be set without a listener.
                
                  on /tmp/tf-test613215798/main.tf line 6:
                  (source code not available)
                
                
        --- PASS: TestAccAWSAppmesh/VirtualNode/tags (63.88s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/basic (27.90s)
        --- FAIL: TestAccAWSAppmesh/VirtualNode/cloudMapServiceDiscovery (85.85s)
            testing.go:683: Step 0 error: errors during apply:
                
                Error: error creating App Mesh virtual node: BadRequestException: Service Discovery can't be set without a listener.
                
                  on /tmp/tf-test199777152/main.tf line 10:
                  (source code not available)
                
                
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	204.956s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAppmesh/VirtualRouter/'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSAppmesh/VirtualRouter/ -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/VirtualRouter
=== RUN   TestAccAWSAppmesh/VirtualRouter/basic
=== RUN   TestAccAWSAppmesh/VirtualRouter/tags
--- FAIL: TestAccAWSAppmesh (35.23s)
    --- FAIL: TestAccAWSAppmesh/VirtualRouter (35.23s)
        --- FAIL: TestAccAWSAppmesh/VirtualRouter/basic (16.93s)
            testing.go:683: Step 0 error: Check failed: Check 5/11 error: aws_appmesh_virtual_router.test: Attribute 'spec.0.listener.#' not found
        --- FAIL: TestAccAWSAppmesh/VirtualRouter/tags (18.30s)
            testing.go:683: Step 0 error: After applying this step, the plan was not empty:
                
                DIFF:
                
                UPDATE: aws_appmesh_virtual_router.test
                  arn:                                       "arn:aws:appmesh:us-west-2:123456789012:mesh/tf-acc-test-5724134345005515619/virtualRouter/tf-acc-test-3283401432193133171" => "arn:aws:appmesh:us-west-2:123456789012:mesh/tf-acc-test-5724134345005515619/virtualRouter/tf-acc-test-3283401432193133171"
                  created_date:                              "2020-05-18T21:14:54Z" => "2020-05-18T21:14:54Z"
                  id:                                        "7016275f-4e6c-4612-8dda-7d41f2ec11bc" => "7016275f-4e6c-4612-8dda-7d41f2ec11bc"
                  last_updated_date:                         "2020-05-18T21:14:54Z" => "2020-05-18T21:14:54Z"
                  mesh_name:                                 "tf-acc-test-5724134345005515619" => "tf-acc-test-5724134345005515619"
                  name:                                      "tf-acc-test-3283401432193133171" => "tf-acc-test-3283401432193133171"
                  spec.#:                                    "1" => "1"
                  spec.0.listener.#:                         "0" => "1"
                  spec.0.listener.0.port_mapping.#:          "" => "1"
                  spec.0.listener.0.port_mapping.0.port:     "" => "8080"
                  spec.0.listener.0.port_mapping.0.protocol: "" => "http"
                  spec.0.service_names.#:                    "" => "0"
                  tags.foo:                                  "bar" => "bar"
                  tags.good:                                 "bad" => "bad"
                
                
                
                STATE:
                
                aws_appmesh_mesh.test:
                  ID = tf-acc-test-5724134345005515619
                  provider = provider.aws
                  arn = arn:aws:appmesh:us-west-2:123456789012:mesh/tf-acc-test-5724134345005515619
                  created_date = 2020-05-18T21:14:52Z
                  last_updated_date = 2020-05-18T21:14:52Z
                  name = tf-acc-test-5724134345005515619
                  spec.# = 1
                aws_appmesh_virtual_router.test:
                  ID = 7016275f-4e6c-4612-8dda-7d41f2ec11bc
                  provider = provider.aws
                  arn = arn:aws:appmesh:us-west-2:123456789012:mesh/tf-acc-test-5724134345005515619/virtualRouter/tf-acc-test-3283401432193133171
                  created_date = 2020-05-18T21:14:54Z
                  last_updated_date = 2020-05-18T21:14:54Z
                  mesh_name = tf-acc-test-5724134345005515619
                  name = tf-acc-test-3283401432193133171
                  spec.# = 1
                  tags.foo = bar
                  tags.good = bad
                
                  Dependencies:
                    aws_appmesh_mesh.test
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	35.261s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1

These errors occur because the flatten/expand routines for the changed attributes (in aws/structure.go) will need to be modified. For example, for aws_appmesh_virtual_router, if I change to

func expandAppmeshVirtualRouterSpec(vSpec []interface{}) *appmesh.VirtualRouterSpec {
	spec := &appmesh.VirtualRouterSpec{}

	if len(vSpec) == 0 || vSpec[0] == nil {
		// Empty Spec is allowed.
		return spec
	}
	mSpec := vSpec[0].(map[string]interface{})

	if vListener, ok := mSpec["listener"].([]interface{}); ok && len(vListener) > 0 && vListener[0] != nil {
		listener := &appmesh.VirtualRouterListener{}

		mListener := vListener[0].(map[string]interface{})

		if vPortMapping, ok := mListener["port_mapping"].([]interface{}); ok && len(vPortMapping) > 0 && vPortMapping[0] != nil {
			mPortMapping := vPortMapping[0].(map[string]interface{})

			listener.PortMapping = &appmesh.PortMapping{}

			if vPort, ok := mPortMapping["port"].(int); ok && vPort > 0 {
				listener.PortMapping.Port = aws.Int64(int64(vPort))
			}
			if vProtocol, ok := mPortMapping["protocol"].(string); ok && vProtocol != "" {
				listener.PortMapping.Protocol = aws.String(vProtocol)
			}
		}

		spec.Listeners = []*appmesh.VirtualRouterListener{listener}
	}

	return spec
}

func flattenAppmeshVirtualRouterSpec(spec *appmesh.VirtualRouterSpec) []interface{} {
	if spec == nil {
		return []interface{}{}
	}

	mSpec := map[string]interface{}{}

	if spec.Listeners != nil && len(spec.Listeners) > 0 {
		listener := spec.Listeners[0]

		mListener := map[string]interface{}{}

		if listener.PortMapping != nil {
			mPortMapping := map[string]interface{}{
				"port":     int(aws.Int64Value(listener.PortMapping.Port)),
				"protocol": aws.StringValue(listener.PortMapping.Protocol),
			}
			mListener["port_mapping"] = []interface{}{mPortMapping}
		}

		mSpec["listener"] = []interface{}{mListener}
	}

	return []interface{}{mSpec}
}

and re-run, I get:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAppmesh/VirtualRouter/'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSAppmesh/VirtualRouter/ -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/VirtualRouter
=== RUN   TestAccAWSAppmesh/VirtualRouter/basic
=== RUN   TestAccAWSAppmesh/VirtualRouter/tags
--- FAIL: TestAccAWSAppmesh (81.55s)
    --- FAIL: TestAccAWSAppmesh/VirtualRouter (81.55s)
        --- FAIL: TestAccAWSAppmesh/VirtualRouter/basic (17.28s)
            testing.go:683: Step 0 error: Check failed: Check 6/11 error: aws_appmesh_virtual_router.test: Attribute 'spec.0.listener.2279702354.port_mapping.#' not found
        --- PASS: TestAccAWSAppmesh/VirtualRouter/tags (64.26s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	81.595s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1

and now the tests should pass if the attribute value is tweaked (2279702354 to 0 in this case).

@ewbankkit
Copy link
Contributor

As I remember, I had these attributes as schema.TypeSet in the initial implementation because the underlying AWS API types accept multiple listeners in an array, although one and only one listener is allowed.
I agree that it's best to simplify for now, and revert to Sets if AWS ever support multiple listeners.

@anGie44
Copy link
Contributor Author

anGie44 commented May 18, 2020

thanks @ewbankkit for running the tests and reviewing! will update as needed

@ghost ghost added size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. and removed size/XS Managed by automation to categorize the size of a PR. labels May 21, 2020
@anGie44
Copy link
Contributor Author

anGie44 commented May 21, 2020

updated @ewbankkit, with acceptance tests passing

@ewbankkit
Copy link
Contributor

Verified acceptance tests:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAppmesh'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSAppmesh -timeout 120m
=== RUN   TestAccAWSAppmesh
=== RUN   TestAccAWSAppmesh/Mesh
=== RUN   TestAccAWSAppmesh/Mesh/egressFilter
=== RUN   TestAccAWSAppmesh/Mesh/tags
=== RUN   TestAccAWSAppmesh/Mesh/basic
=== RUN   TestAccAWSAppmesh/Route
=== RUN   TestAccAWSAppmesh/Route/tags
=== RUN   TestAccAWSAppmesh/Route/httpHeader
=== RUN   TestAccAWSAppmesh/Route/httpRoute
=== RUN   TestAccAWSAppmesh/Route/tcpRoute
=== RUN   TestAccAWSAppmesh/Route/routePriority
=== RUN   TestAccAWSAppmesh/VirtualNode
=== RUN   TestAccAWSAppmesh/VirtualNode/basic
=== RUN   TestAccAWSAppmesh/VirtualNode/cloudMapServiceDiscovery
=== RUN   TestAccAWSAppmesh/VirtualNode/listenerHealthChecks
=== RUN   TestAccAWSAppmesh/VirtualNode/logging
=== RUN   TestAccAWSAppmesh/VirtualNode/tags
=== RUN   TestAccAWSAppmesh/VirtualRouter
=== RUN   TestAccAWSAppmesh/VirtualRouter/basic
=== RUN   TestAccAWSAppmesh/VirtualRouter/tags
=== RUN   TestAccAWSAppmesh/VirtualService
=== RUN   TestAccAWSAppmesh/VirtualService/virtualNode
=== RUN   TestAccAWSAppmesh/VirtualService/virtualRouter
=== RUN   TestAccAWSAppmesh/VirtualService/tags
--- PASS: TestAccAWSAppmesh (989.12s)
    --- PASS: TestAccAWSAppmesh/Mesh (132.08s)
        --- PASS: TestAccAWSAppmesh/Mesh/egressFilter (51.55s)
        --- PASS: TestAccAWSAppmesh/Mesh/tags (56.48s)
        --- PASS: TestAccAWSAppmesh/Mesh/basic (24.06s)
    --- PASS: TestAccAWSAppmesh/Route (278.10s)
        --- PASS: TestAccAWSAppmesh/Route/tags (72.96s)
        --- PASS: TestAccAWSAppmesh/Route/httpHeader (51.70s)
        --- PASS: TestAccAWSAppmesh/Route/httpRoute (51.96s)
        --- PASS: TestAccAWSAppmesh/Route/tcpRoute (49.51s)
        --- PASS: TestAccAWSAppmesh/Route/routePriority (51.96s)
    --- PASS: TestAccAWSAppmesh/VirtualNode (303.57s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/basic (28.52s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/cloudMapServiceDiscovery (118.19s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/listenerHealthChecks (46.55s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/logging (45.45s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/tags (64.85s)
    --- PASS: TestAccAWSAppmesh/VirtualRouter (108.57s)
        --- PASS: TestAccAWSAppmesh/VirtualRouter/basic (45.43s)
        --- PASS: TestAccAWSAppmesh/VirtualRouter/tags (63.14s)
    --- PASS: TestAccAWSAppmesh/VirtualService (166.80s)
        --- PASS: TestAccAWSAppmesh/VirtualService/virtualNode (50.30s)
        --- PASS: TestAccAWSAppmesh/VirtualService/virtualRouter (46.98s)
        --- PASS: TestAccAWSAppmesh/VirtualService/tags (69.50s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	989.185s

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.

Confirming it looks good to me too. 😄 Thank you Kit for all your help.

Output from acceptance testing:

--- PASS: TestAccAWSAppmesh (337.70s)
    --- PASS: TestAccAWSAppmesh/VirtualService (44.60s)
        --- PASS: TestAccAWSAppmesh/VirtualService/virtualNode (13.99s)
        --- PASS: TestAccAWSAppmesh/VirtualService/virtualRouter (12.48s)
        --- PASS: TestAccAWSAppmesh/VirtualService/tags (18.14s)
    --- PASS: TestAccAWSAppmesh/Mesh (40.53s)
        --- PASS: TestAccAWSAppmesh/Mesh/tags (17.30s)
        --- PASS: TestAccAWSAppmesh/Mesh/basic (7.61s)
        --- PASS: TestAccAWSAppmesh/Mesh/egressFilter (15.62s)
    --- PASS: TestAccAWSAppmesh/Route (71.78s)
        --- PASS: TestAccAWSAppmesh/Route/httpHeader (13.04s)
        --- PASS: TestAccAWSAppmesh/Route/httpRoute (13.44s)
        --- PASS: TestAccAWSAppmesh/Route/tcpRoute (13.25s)
        --- PASS: TestAccAWSAppmesh/Route/routePriority (13.46s)
        --- PASS: TestAccAWSAppmesh/Route/tags (18.59s)
    --- PASS: TestAccAWSAppmesh/VirtualNode (150.62s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/basic (8.05s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/cloudMapServiceDiscovery (98.88s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/listenerHealthChecks (12.98s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/logging (13.02s)
        --- PASS: TestAccAWSAppmesh/VirtualNode/tags (17.70s)
    --- PASS: TestAccAWSAppmesh/VirtualRouter (30.17s)
        --- PASS: TestAccAWSAppmesh/VirtualRouter/basic (12.34s)
        --- PASS: TestAccAWSAppmesh/VirtualRouter/tags (17.83s)

@anGie44 anGie44 merged commit 30e4848 into master May 21, 2020
@anGie44 anGie44 deleted the ap_typelist_appmesh branch May 21, 2020 14:43
@ghost
Copy link

ghost commented Jun 20, 2020

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 Jun 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/appmesh Issues and PRs that pertain to the appmesh service. size/L Managed by automation to categorize the size of a PR. technical-debt Addresses areas of the codebase that need refactoring or redesign. 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