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

r/aws_ssm_maintenance_window_target: Change MaxItems of targets #2361

Merged
merged 4 commits into from
Nov 21, 2017

Conversation

atsushi-ishibashi
Copy link
Contributor

@atsushi-ishibashi atsushi-ishibashi commented Nov 18, 2017

#2225
Not yet testacc.
According to Docs, minimum number is 0.
But I got a validation error and I'm asking aws-sdk-go.

ValidationException: 1 validation error detected: Value '[]' at 'targets' failed to satisfy constraint: Member must have length greater than or equal to 1

Copy link
Contributor

@Ninir Ninir left a comment

Choose a reason for hiding this comment

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

Hi @atsushi-ishibashi

Thanks a lot for the work :)
Even though it is WIP, just left comments as it might help you!

@@ -30,9 +30,9 @@ func resourceAwsSsmMaintenanceWindowTarget() *schema.Resource {

"targets": {
Type: schema.TypeList,
Required: true,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

As you said the documentation exposes that this seems required.

Let's keep it required here, the documentation is wrong on the number of items being 0. (you can even provide this feedback to AWS if you want :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure👍

aws/structure.go Outdated
@@ -2685,13 +2685,13 @@ func flattenAwsSsmTargets(targets []*ssm.Target) []map[string]interface{} {
}

result := make([]map[string]interface{}, 0, len(targets))
target := targets[0]
for _, target := range targets {
t := make(map[string]interface{})
Copy link
Contributor

@Ninir Ninir Nov 20, 2017

Choose a reason for hiding this comment

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

Nitpick: To be more memory-efficient, we could set: make(map[string]interface{}, 1), thoughts? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems the same

func hoge1() {
	results := make([]map[string]interface{}, 100)
	for i := range results {
		t := make(map[string]interface{})
		t["key"], t["values"] = "key", "value"
		results[i] = t
	}
}

func hoge2() {
	results := make([]map[string]interface{}, 100)
	for i := range results {
		t := make(map[string]interface{}, 1)
		t["key"], t["values"] = "key", "value"
		results[i] = t
	}
}

func hoge3() {
	results := make([]map[string]interface{}, 100)
	for i := range results {
		t := map[string]interface{}{}
		t["key"], t["values"] = "key", "value"
		results[i] = t
	}
}

func BenchmarkHoge1(b *testing.B) {
	for i := 0; i < b.N; i++ {
		hoge1()
	}
}

func BenchmarkHoge2(b *testing.B) {
	for i := 0; i < b.N; i++ {
		hoge2()
	}
}

func BenchmarkHoge3(b *testing.B) {
	for i := 0; i < b.N; i++ {
		hoge3()
	}
}
go test -bench BenchmarkHoge -benchmem
BenchmarkHoge1-4   	   50000	     32459 ns/op	   33600 B/op	     200 allocs/op
BenchmarkHoge2-4   	   50000	     32529 ns/op	   33600 B/op	     200 allocs/op
BenchmarkHoge3-4   	   50000	     36636 ns/op	   33600 B/op	     200 allocs/op

Copy link
Contributor

Choose a reason for hiding this comment

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

Third option is even better, interesting 🤔
Still, can you go for the second one, since it has a fixed size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok👍

@Ninir Ninir added the enhancement Requests to existing resources that expand the functionality or scope. label Nov 20, 2017
@atsushi-ishibashi
Copy link
Contributor Author

make testacc TEST=./aws TESTARGS='-run=TestAccAWSSSMMaintenanceWindowTarget_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSSSMMaintenanceWindowTarget_basic -timeout 120m
=== RUN   TestAccAWSSSMMaintenanceWindowTarget_basic
--- PASS: TestAccAWSSSMMaintenanceWindowTarget_basic (52.91s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	52.970s

@atsushi-ishibashi atsushi-ishibashi changed the title [WIP]r/aws_ssm_maintenance_window_target: Change MaxItems of targets r/aws_ssm_maintenance_window_target: Change MaxItems of targets Nov 20, 2017
@@ -36,11 +36,11 @@ The following arguments are supported:

* `window_id` - (Required) The Id of the maintenance window to register the target with.
* `resource_type` - (Required) The type of target being registered with the Maintenance Window. Possible values `INSTANCE`.
* `targets` - (Required) The targets (either instances or tags). Instances are specified using Key=instanceids,Values=instanceid1,instanceid2. Tags are specified using Key=tag name,Values=tag value.
* `targets` - (Required) The targets (either instances or tags). Instances are specified using Key=instanceids,Values=instanceid1,instanceid2. Tags are specified using Key=tag name,Values=tag value. Minimum number of 0 items. Maximum number of 5 items.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove the first part of the change, since it is required? thanks

Copy link
Contributor

@Ninir Ninir left a comment

Choose a reason for hiding this comment

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

Hi @atsushi-ishibashi

Just added 2 checks in an acceptance test to ensure we do have multiple target in the state.

make testacc TEST=./aws TESTARGS='-run=TestAccAWSSSMMaintenanceWindow'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSSSMMaintenanceWindow -timeout 120m
=== RUN   TestAccAWSSSMMaintenanceWindowTarget_basic
--- PASS: TestAccAWSSSMMaintenanceWindowTarget_basic (26.65s)
=== RUN   TestAccAWSSSMMaintenanceWindowTask_basic
--- PASS: TestAccAWSSSMMaintenanceWindowTask_basic (123.93s)
=== RUN   TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource
--- PASS: TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource (151.63s)
=== RUN   TestAccAWSSSMMaintenanceWindow_basic
--- PASS: TestAccAWSSSMMaintenanceWindow_basic (38.68s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	340.963s

Looks very good to me, thanks for the work & reactivity! 👍

@ghost
Copy link

ghost commented Apr 10, 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 Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants