Skip to content

Commit

Permalink
resource/aws_ssm_maintenance_window_task: Remove deprecated logging_i…
Browse files Browse the repository at this point in the history
…nfo and task_parameters configuration blocks

Reference: #7823
Reference: #13398

Output from acceptance testing:

```
--- PASS: TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig (13.56s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters (14.66s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource (22.46s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_basic (22.75s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters (36.30s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters (36.56s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters (39.53s)
```
  • Loading branch information
bflad committed Jul 23, 2020
1 parent 029fe81 commit 9f1609e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 267 deletions.
135 changes: 3 additions & 132 deletions aws/resource_aws_ssm_maintenance_window_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,55 +92,10 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource {
Optional: true,
},

"logging_info": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ConflictsWith: []string{"task_invocation_parameters"},
Deprecated: "use 'task_invocation_parameters' argument instead",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"s3_bucket_name": {
Type: schema.TypeString,
Required: true,
},
"s3_region": {
Type: schema.TypeString,
Required: true,
},
"s3_bucket_prefix": {
Type: schema.TypeString,
Optional: true,
},
},
},
},

"task_parameters": {
Type: schema.TypeSet,
Optional: true,
ConflictsWith: []string{"task_invocation_parameters"},
Deprecated: "use 'task_invocation_parameters' argument instead",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"values": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},

"task_invocation_parameters": {
Type: schema.TypeList,
Optional: true,
ConflictsWith: []string{"task_parameters", "logging_info"},
MaxItems: 1,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"automation_parameters": {
Expand Down Expand Up @@ -328,62 +283,6 @@ func resourceAwsSsmMaintenanceWindowTask() *schema.Resource {
}
}

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

loggingConfig := config[0].(map[string]interface{})

loggingInfo := &ssm.LoggingInfo{
S3BucketName: aws.String(loggingConfig["s3_bucket_name"].(string)),
S3Region: aws.String(loggingConfig["s3_region"].(string)),
}

if s := loggingConfig["s3_bucket_prefix"].(string); s != "" {
loggingInfo.S3KeyPrefix = aws.String(s)
}

return loggingInfo
}

func flattenAwsSsmMaintenanceWindowLoggingInfo(loggingInfo *ssm.LoggingInfo) []interface{} {

result := make(map[string]interface{})
result["s3_bucket_name"] = *loggingInfo.S3BucketName
result["s3_region"] = *loggingInfo.S3Region

if loggingInfo.S3KeyPrefix != nil {
result["s3_bucket_prefix"] = *loggingInfo.S3KeyPrefix
}

return []interface{}{result}
}

func expandAwsSsmTaskParameters(config []interface{}) map[string]*ssm.MaintenanceWindowTaskParameterValueExpression {
params := make(map[string]*ssm.MaintenanceWindowTaskParameterValueExpression)
for _, v := range config {
paramConfig := v.(map[string]interface{})
params[paramConfig["name"].(string)] = &ssm.MaintenanceWindowTaskParameterValueExpression{
Values: expandStringList(paramConfig["values"].([]interface{})),
}
}
return params
}

func flattenAwsSsmTaskParameters(taskParameters map[string]*ssm.MaintenanceWindowTaskParameterValueExpression) []interface{} {
result := make([]interface{}, 0, len(taskParameters))
for k, v := range taskParameters {
taskParam := map[string]interface{}{
"name": k,
"values": flattenStringList(v.Values),
}
result = append(result, taskParam)
}

return result
}

func expandAwsSsmTaskInvocationParameters(config []interface{}) *ssm.MaintenanceWindowTaskInvocationParameters {
if len(config) == 0 || config[0] == nil {
return nil
Expand Down Expand Up @@ -697,14 +596,6 @@ func resourceAwsSsmMaintenanceWindowTaskCreate(d *schema.ResourceData, meta inte
params.Priority = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("logging_info"); ok {
params.LoggingInfo = expandAwsSsmMaintenanceWindowLoggingInfo(v.([]interface{}))
}

if v, ok := d.GetOk("task_parameters"); ok {
params.TaskParameters = expandAwsSsmTaskParameters(v.(*schema.Set).List())
}

if v, ok := d.GetOk("task_invocation_parameters"); ok {
params.TaskInvocationParameters = expandAwsSsmTaskInvocationParameters(v.([]interface{}))
}
Expand Down Expand Up @@ -747,18 +638,6 @@ func resourceAwsSsmMaintenanceWindowTaskRead(d *schema.ResourceData, meta interf
d.Set("name", resp.Name)
d.Set("description", resp.Description)

if resp.LoggingInfo != nil {
if err := d.Set("logging_info", flattenAwsSsmMaintenanceWindowLoggingInfo(resp.LoggingInfo)); err != nil {
return fmt.Errorf("Error setting logging_info error: %#v", err)
}
}

if resp.TaskParameters != nil {
if err := d.Set("task_parameters", flattenAwsSsmTaskParameters(resp.TaskParameters)); err != nil {
return fmt.Errorf("Error setting task_parameters error: %#v", err)
}
}

if resp.TaskInvocationParameters != nil {
if err := d.Set("task_invocation_parameters", flattenAwsSsmTaskInvocationParameters(resp.TaskInvocationParameters)); err != nil {
return fmt.Errorf("Error setting task_invocation_parameters error: %#v", err)
Expand Down Expand Up @@ -799,14 +678,6 @@ func resourceAwsSsmMaintenanceWindowTaskUpdate(d *schema.ResourceData, meta inte
params.Priority = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("logging_info"); ok {
params.LoggingInfo = expandAwsSsmMaintenanceWindowLoggingInfo(v.([]interface{}))
}

if v, ok := d.GetOk("task_parameters"); ok {
params.TaskParameters = expandAwsSsmTaskParameters(v.(*schema.Set).List())
}

if v, ok := d.GetOk("task_invocation_parameters"); ok {
params.TaskInvocationParameters = expandAwsSsmTaskInvocationParameters(v.([]interface{}))
}
Expand Down
142 changes: 21 additions & 121 deletions aws/resource_aws_ssm_maintenance_window_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,32 +220,6 @@ func TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters(t *
})
}

func TestAccAWSSSMMaintenanceWindowTask_TaskParameters(t *testing.T) {
var task ssm.MaintenanceWindowTask
resourceName := "aws_ssm_maintenance_window_task.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSSMMaintenanceWindowTaskDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSSMMaintenanceWindowTaskConfigTaskParametersMultiple(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSSMMaintenanceWindowTaskExists(resourceName, &task),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccAWSSSMMaintenanceWindowTaskImportStateIdFunc(resourceName),
ImportStateVerify: true,
},
},
})
}

func TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig(t *testing.T) {
var task ssm.MaintenanceWindowTask
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -432,9 +406,13 @@ resource "aws_ssm_maintenance_window_task" "test" {
values = ["${aws_ssm_maintenance_window_target.test.id}"]
}
task_parameters {
name = "commands"
values = ["pwd"]
task_invocation_parameters {
run_command_parameters {
parameter {
name = "commands"
values = ["pwd"]
}
}
}
}
Expand All @@ -460,9 +438,13 @@ resource "aws_ssm_maintenance_window_task" "test" {
values = ["${aws_ssm_maintenance_window_target.test.id}"]
}
task_parameters {
name = "commands"
values = ["pwd"]
task_invocation_parameters {
run_command_parameters {
parameter {
name = "commands"
values = ["pwd"]
}
}
}
}
Expand Down Expand Up @@ -523,9 +505,13 @@ resource "aws_ssm_maintenance_window_task" "test" {
values = ["${aws_ssm_maintenance_window_target.test.id}"]
}
task_parameters {
name = "commands"
values = ["date"]
task_invocation_parameters {
run_command_parameters {
parameter {
name = "commands"
values = ["date"]
}
}
}
}
Expand Down Expand Up @@ -768,89 +754,3 @@ resource "aws_ssm_maintenance_window_task" "test" {
}
`, rName)
}

func testAccAWSSSMMaintenanceWindowTaskConfigTaskParametersMultiple(rName string) string {
return fmt.Sprintf(`
resource "aws_ssm_maintenance_window" "test" {
cutoff = 1
duration = 3
name = %[1]q
schedule = "cron(0 16 ? * TUE *)"
}
resource "aws_ssm_maintenance_window_target" "test" {
name = %[1]q
resource_type = "INSTANCE"
window_id = "${aws_ssm_maintenance_window.test.id}"
targets {
key = "tag:Name"
values = ["tf-acc-test"]
}
}
resource "aws_iam_role" "test" {
name = %[1]q
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "events.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}
resource "aws_iam_role_policy" "test" {
name = %[1]q
role = "${aws_iam_role.test.name}"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "ssm:*",
"Resource": "*"
}
}
POLICY
}
resource "aws_ssm_maintenance_window_task" "test" {
max_concurrency = 1
max_errors = 1
priority = 1
service_role_arn = "${aws_iam_role.test.arn}"
task_arn = "AWS-RunRemoteScript"
task_type = "RUN_COMMAND"
window_id = "${aws_ssm_maintenance_window.test.id}"
targets {
key = "WindowTargetIds"
values = ["${aws_ssm_maintenance_window_target.test.id}"]
}
task_parameters {
name = "sourceType"
values = ["s3"]
}
task_parameters {
name = "sourceInfo"
values = ["https://s3.amazonaws.com/bucket"]
}
task_parameters {
name = "commandLine"
values = ["date"]
}
}
`, rName)
}
Loading

0 comments on commit 9f1609e

Please sign in to comment.