-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Conversation
There was a problem hiding this 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!
Hello @Ninir, as discussed with you, I've added the two new validators and updated the test to check the name and description. |
There was a problem hiding this 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, |
There was a problem hiding this comment.
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),
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
FYI the documentation also lives in |
Updates are done 🤞 |
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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!
There was a problem hiding this 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)
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. |
@Guimove @bflad @Ninir just a heads up that the validation on the |
Please see #7186 which fixes this PR. |
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! |
Fixes #5702
Changes proposed in this pull request:
Output from acceptance testing:
@Ninir : Please be kind, this is my first contrib :)