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

add name and description to SSM Maintenance Window Tasks #5762

Merged
merged 7 commits into from
Nov 14, 2018

Conversation

Guimove
Copy link
Contributor

@Guimove Guimove commented Sep 4, 2018

Fixes #5702

Changes proposed in this pull request:

  • Add the name and description fields in terraform when creating SSM Maintenance window tasks

Output from acceptance testing:

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 (20.48s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	20.497s

...

@Ninir : Please be kind, this is my first contrib :)

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.

Hey @Guimove!

Thank you so much for your contribution! Nice first shot 😄

Just left a few comments prior to testing. Let me know if you need any help in this!

aws/resource_aws_ssm_maintenance_window_task.go Outdated Show resolved Hide resolved
aws/resource_aws_ssm_maintenance_window_task.go Outdated Show resolved Hide resolved
@Ninir Ninir added enhancement Requests to existing resources that expand the functionality or scope. service/ssm Issues and PRs that pertain to the ssm service. labels Sep 4, 2018
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Sep 4, 2018
@Guimove
Copy link
Contributor Author

Guimove commented Sep 10, 2018

Hello @Ninir, as discussed with you, I've added the two new validators and updated the test to check the name and description.
Thanks

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.

Looking good, @Guimove! A few minor bits and this should be ready. 👍

Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateAwsSSMMaintenanceWindowTaskDescription,
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use an upstream validation function here instead of our own custom one: https://godoc.org/github.com/hashicorp/terraform/helper/validation#StringLenBetween

ValidateFunc: validation.StringLenBetween(0, 128),

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 for the description but for the name I can keep my validator that check the regex and the length ?

@@ -241,6 +257,14 @@ func resourceAwsSsmMaintenanceWindowTaskRead(d *schema.ResourceData, meta interf
d.Set("task_arn", t.TaskArn)
d.Set("priority", t.Priority)

if t.Name != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

d.Set() automatically handles conversions of types like *string and we prefer to always call d.Set() for drift detection. (Same with description below)

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 I'll remove that if

@@ -141,6 +143,8 @@ resource "aws_ssm_maintenance_window_task" "target" {
task_type = "RUN_COMMAND"
task_arn = "AWS-RunShellScript"
priority = 1
name = "TestMaintenanceWindowTask"
description = "This ressource is for test purpose only"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Typo ressource should be resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the french touch hehe

@bflad
Copy link
Contributor

bflad commented Sep 11, 2018

FYI the documentation also lives in website/docs/r/ssm_maintenance_window_task.html.md for updating that as well. 😄

@ghost ghost added the size/M Managed by automation to categorize the size of a PR. label Sep 14, 2018
@Guimove
Copy link
Contributor Author

Guimove commented Sep 14, 2018

Updates are done 🤞

@ghost ghost added size/S Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. service/ssm Issues and PRs that pertain to the ssm service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. and removed size/M Managed by automation to categorize the size of a PR. labels Sep 20, 2018
"name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Copy link
Contributor

@Ninir Ninir Sep 26, 2018

Choose a reason for hiding this comment

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

Is this really forcing a new resource? The API seems to tell the opposite (i.e. it's updatable): https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_UpdateMaintenanceWindowTask.html

"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@@ -213,6 +217,8 @@ resource "aws_ssm_maintenance_window_task" "target" {
task_type = "RUN_COMMAND"
task_arn = "AWS-RunShellScript"
priority = 1
name = "TestMaintenanceWindowTask"
description = "This resource is for test purpose only"
Copy link
Contributor

Choose a reason for hiding this comment

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

Since they seem to be updatable, we would then be able to make a change to these 2 lines to ensure the update for name and description is OK, as in:

  name = "TestMaintenanceWindowTaskUpdate"
  description = "This resource is for update purpose only"

Thus, we could update TestAccAWSSSMMaintenanceWindowTask_basic for instance to add another TestStep section, as in:

 func TestAccAWSSSMMaintenanceWindowTask_basic(t *testing.T) {
 	var task ssm.MaintenanceWindowTask
 
 	name := acctest.RandString(10)
 	resource.Test(t, resource.TestCase{
 		PreCheck:     func() { testAccPreCheck(t) },
 		Providers:    testAccProviders,
 		CheckDestroy: testAccCheckAWSSSMMaintenanceWindowTaskDestroy,
 		Steps: []resource.TestStep{
 			{
				Config: testAccAWSSSMMaintenanceWindowTaskBasicConfig(name),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckAWSSSMMaintenanceWindowTaskExists("aws_ssm_maintenance_window_task.target", &task),
					resource.TestCheckResourceAttr("aws_ssm_maintenance_window_task.target", "name", "TestMaintenanceWindowTask"),
					resource.TestCheckResourceAttr("aws_ssm_maintenance_window_task.target", "description", "This ressource is for test purpose only"),
				),
			},
 			{
				Config: testAccAWSSSMMaintenanceWindowTaskBasicConfigUpdated(name),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckAWSSSMMaintenanceWindowTaskExists("aws_ssm_maintenance_window_task.target", &task),
					resource.TestCheckResourceAttr("aws_ssm_maintenance_window_task.target", "name", "TestMaintenanceWindowTaskUpdate"),
					resource.TestCheckResourceAttr("aws_ssm_maintenance_window_task.target", "description", "This ressource is for update purpose only"),
				),
			},
		},
 	})
 }

Tell me if you need any help on that!

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 so much @Guimove! Since we haven't heard back in awhile and to not hold up further development, I've gone ahead and added a commit which fixes the merge conflict and typo in the acceptance test. We can treat the lack of SSM Maintenance Window Task updates as a separate enhancement. 👍

--- PASS: TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource (130.55s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_basic (228.94s)

@bflad bflad merged commit dbb2e31 into hashicorp:master Nov 14, 2018
bflad added a commit that referenced this pull request Nov 14, 2018
@bflad
Copy link
Contributor

bflad commented Nov 15, 2018

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

@lorengordon
Copy link
Contributor

@Guimove @bflad @Ninir just a heads up that the validation on the name and desciption parameters appears to be running even when the parameters are not passed. The parameters are marked as optional, so this seems counter-intuitive. That's what is causing this issue, which we also just encountered trying to use the community module terraform-aws-ssm-patch-management.

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Dec 14, 2018
@YakDriver
Copy link
Member

Please see #7186 which fixes this PR.

@ghost
Copy link

ghost commented Apr 1, 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 1, 2020
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/ssm Issues and PRs that pertain to the ssm service. size/S 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.

Add name and description to SSM Maintenance Window Tasks
5 participants