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

maintenance window task cloudwatch config #12167

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions aws/resource_aws_ssm_maintenance_window_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cloudwatch_output_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cloudwatch_log_group_name": {
Type: schema.TypeString,
Optional: true,
},
"cloudwatch_output_enabled": {
Type: schema.TypeBool,
Required: true,
},
},
},
},

"comment": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -500,6 +518,10 @@ func expandAwsSsmTaskInvocationRunCommandParameters(config []interface{}) *ssm.M

params := &ssm.MaintenanceWindowRunCommandParameters{}
configParam := config[0].(map[string]interface{})

if attr, ok := configParam["cloudwatch_output_config"]; ok && len(attr.([]interface{})) > 0 {
params.CloudWatchOutputConfig = expandAwsSsmTaskInvocationRunCommandParametersCloudwatchOutputConfig(attr.([]interface{}))
}
if attr, ok := configParam["comment"]; ok && len(attr.(string)) != 0 {
params.Comment = aws.String(attr.(string))
}
Expand Down Expand Up @@ -533,6 +555,9 @@ func expandAwsSsmTaskInvocationRunCommandParameters(config []interface{}) *ssm.M
func flattenAwsSsmTaskInvocationRunCommandParameters(parameters *ssm.MaintenanceWindowRunCommandParameters) []interface{} {
result := make(map[string]interface{})

if parameters.CloudWatchOutputConfig != nil {
result["cloudwatch_output_config"] = flattenAwsSsmTaskInvocationRunCommandParametersCloudwatchOutputConfig(parameters.CloudWatchOutputConfig)
}
if parameters.Comment != nil {
result["comment"] = aws.StringValue(parameters.Comment)
}
Expand Down Expand Up @@ -594,6 +619,24 @@ func flattenAwsSsmTaskInvocationStepFunctionsParameters(parameters *ssm.Maintena
return []interface{}{result}
}

func expandAwsSsmTaskInvocationRunCommandParametersCloudwatchOutputConfig(config []interface{}) *ssm.CloudWatchOutputConfig {
if len(config) == 0 || config[0] == nil {
return nil
}

params := &ssm.CloudWatchOutputConfig{}
configParam := config[0].(map[string]interface{})

if attr, ok := configParam["cloudwatch_log_group_name"]; ok && len(attr.(string)) != 0 {
params.CloudWatchLogGroupName = aws.String(attr.(string))
}
if attr, ok := configParam["cloudwatch_output_enabled"]; ok {
params.CloudWatchOutputEnabled = aws.Bool(attr.(bool))
}

return params
}

func expandAwsSsmTaskInvocationRunCommandParametersNotificationConfig(config []interface{}) *ssm.NotificationConfig {
if len(config) == 0 || config[0] == nil {
return nil
Expand All @@ -615,6 +658,19 @@ func expandAwsSsmTaskInvocationRunCommandParametersNotificationConfig(config []i
return params
}

func flattenAwsSsmTaskInvocationRunCommandParametersCloudwatchOutputConfig(config *ssm.CloudWatchOutputConfig) []interface{} {
result := make(map[string]interface{})

if config.CloudWatchLogGroupName != nil {
result["cloudwatch_log_group_name"] = aws.StringValue(config.CloudWatchLogGroupName)
}
if config.CloudWatchOutputEnabled != nil {
result["cloudwatch_output_enabled"] = aws.BoolValue(config.CloudWatchOutputEnabled)
}

return []interface{}{result}
}

func flattenAwsSsmTaskInvocationRunCommandParametersNotificationConfig(config *ssm.NotificationConfig) []interface{} {
result := make(map[string]interface{})

Expand Down
10 changes: 10 additions & 0 deletions aws/resource_aws_ssm_maintenance_window_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters(t *te
resourceName := "aws_ssm_maintenance_window_task.test"
serviceRoleResourceName := "aws_iam_role.test"
s3BucketResourceName := "aws_s3_bucket.foo"
cloudwatchLogGroupResourceName := "aws_cloudwatch_log_group.foo"

name := acctest.RandString(10)
resource.ParallelTest(t, resource.TestCase{
Expand All @@ -182,6 +183,7 @@ func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters(t *te
resource.TestCheckResourceAttr(resourceName, "task_invocation_parameters.0.run_command_parameters.0.comment", "test comment update"),
resource.TestCheckResourceAttr(resourceName, "task_invocation_parameters.0.run_command_parameters.0.timeout_seconds", "60"),
resource.TestCheckResourceAttrPair(resourceName, "task_invocation_parameters.0.run_command_parameters.0.output_s3_bucket", s3BucketResourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "task_invocation_parameters.0.run_command_parameters.0.cloudwatch_output_config.0.cloudwatch_log_group_name", cloudwatchLogGroupResourceName, "name"),
),
},
{
Expand Down Expand Up @@ -704,6 +706,10 @@ resource "aws_s3_bucket" "foo" {
force_destroy = true
}

resource "aws_cloudwatch_log_group" "foo" {
name = "foo"
}

resource "aws_ssm_maintenance_window_task" "test" {
window_id = "${aws_ssm_maintenance_window.test.id}"
task_type = "RUN_COMMAND"
Expand All @@ -725,6 +731,10 @@ resource "aws_ssm_maintenance_window_task" "test" {
timeout_seconds = %[3]d
output_s3_bucket = "${aws_s3_bucket.foo.id}"
output_s3_key_prefix = "foo"
cloudwatch_output_config {
cloudwatch_log_group_name = "${aws_cloudwatch_log_group.foo.name}"
cloudwatch_output_enabled = true
}
parameter {
name = "commands"
values = ["date"]
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/ssm_maintenance_window_task.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ The following arguments are supported:

`run_command_parameters` supports the following:

* `cloudwatch_output_config` - (Optional) Configuration for sending command execution logs to CloudWatch Logs. Documented below.
* `comment` - (Optional) Information about the command(s) to execute.
* `document_hash` - (Optional) The SHA-256 or SHA-1 hash created by the system when the document was created. SHA-1 hashes have been deprecated.
* `document_hash_type` - (Optional) SHA-256 or SHA-1. SHA-1 hashes have been deprecated. Valid values: `Sha256` and `Sha1`
Expand All @@ -197,6 +198,11 @@ The following arguments are supported:
* `input` - (Optional) The inputs for the STEP_FUNCTION task.
* `name` - (Optional) The name of the STEP_FUNCTION task.

`cloudwatch_output_config` supports the following:

* `cloudwatch_log_group_name` - (Optional) The name of the CloudWatch log group to send command output. If you don't specify a group name, Systems Manager automatically creates a log group for you.
* `cloudwatch_output_enabled` - (Required) Enable logging command output to CloudWatch Logs.

`notification_config` supports the following:

* `notification_arn` - (Optional) An Amazon Resource Name (ARN) for a Simple Notification Service (SNS) topic. Run Command pushes notifications about command status changes to this topic.
Expand Down