From fce5f99a39df2acd0d02bee1632834fafa8066c2 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 24 May 2020 11:43:33 +0300 Subject: [PATCH] disappears test use aws value funcs --- aws/resource_aws_cloudwatch_event_target.go | 30 +++++++++---------- ...source_aws_cloudwatch_event_target_test.go | 27 ++++++++++++++++- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/aws/resource_aws_cloudwatch_event_target.go b/aws/resource_aws_cloudwatch_event_target.go index 20d3323f2f5..55e13a78d00 100644 --- a/aws/resource_aws_cloudwatch_event_target.go +++ b/aws/resource_aws_cloudwatch_event_target.go @@ -118,13 +118,11 @@ func resourceAwsCloudWatchEventTarget() *schema.Resource { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, }, "subnets": { Type: schema.TypeSet, Required: true, Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, }, "assign_public_ip": { Type: schema.TypeBool, @@ -357,7 +355,7 @@ func findEventTargetById(id, rule string, nextToken *string, conn *events.CloudW } for _, t := range out.Targets { - if *t.Id == id { + if aws.StringValue(t.Id) == id { return t, nil } } @@ -585,7 +583,7 @@ func flattenAwsCloudWatchEventTargetRunParameters(runCommand *events.RunCommandP for _, x := range runCommand.RunCommandTargets { config := make(map[string]interface{}) - config["key"] = *x.Key + config["key"] = aws.StringValue(x.Key) config["values"] = flattenStringList(x.Values) result = append(result, config) @@ -596,17 +594,17 @@ func flattenAwsCloudWatchEventTargetRunParameters(runCommand *events.RunCommandP func flattenAwsCloudWatchEventTargetEcsParameters(ecsParameters *events.EcsParameters) []map[string]interface{} { config := make(map[string]interface{}) if ecsParameters.Group != nil { - config["group"] = *ecsParameters.Group + config["group"] = aws.StringValue(ecsParameters.Group) } if ecsParameters.LaunchType != nil { - config["launch_type"] = *ecsParameters.LaunchType + config["launch_type"] = aws.StringValue(ecsParameters.LaunchType) } config["network_configuration"] = flattenAwsCloudWatchEventTargetEcsParametersNetworkConfiguration(ecsParameters.NetworkConfiguration) if ecsParameters.PlatformVersion != nil { - config["platform_version"] = *ecsParameters.PlatformVersion + config["platform_version"] = aws.StringValue(ecsParameters.PlatformVersion) } - config["task_count"] = *ecsParameters.TaskCount - config["task_definition_arn"] = *ecsParameters.TaskDefinitionArn + config["task_count"] = aws.Int64Value(ecsParameters.TaskCount) + config["task_definition_arn"] = aws.StringValue(ecsParameters.TaskDefinitionArn) result := []map[string]interface{}{config} return result } @@ -616,11 +614,11 @@ func flattenAwsCloudWatchEventTargetEcsParametersNetworkConfiguration(nc *events } result := make(map[string]interface{}) - result["security_groups"] = schema.NewSet(schema.HashString, flattenStringList(nc.AwsvpcConfiguration.SecurityGroups)) - result["subnets"] = schema.NewSet(schema.HashString, flattenStringList(nc.AwsvpcConfiguration.Subnets)) + result["security_groups"] = flattenStringSet(nc.AwsvpcConfiguration.SecurityGroups) + result["subnets"] = flattenStringSet(nc.AwsvpcConfiguration.Subnets) if nc.AwsvpcConfiguration.AssignPublicIp != nil { - result["assign_public_ip"] = *nc.AwsvpcConfiguration.AssignPublicIp == events.AssignPublicIpEnabled + result["assign_public_ip"] = aws.StringValue(nc.AwsvpcConfiguration.AssignPublicIp) == events.AssignPublicIpEnabled } return []interface{}{result} @@ -642,14 +640,14 @@ func flattenAwsCloudWatchEventTargetBatchParameters(batchParameters *events.Batc func flattenAwsCloudWatchEventTargetKinesisParameters(kinesisParameters *events.KinesisParameters) []map[string]interface{} { config := make(map[string]interface{}) - config["partition_key_path"] = *kinesisParameters.PartitionKeyPath + config["partition_key_path"] = aws.StringValue(kinesisParameters.PartitionKeyPath) result := []map[string]interface{}{config} return result } func flattenAwsCloudWatchEventTargetSqsParameters(sqsParameters *events.SqsParameters) []map[string]interface{} { config := make(map[string]interface{}) - config["message_group_id"] = *sqsParameters.MessageGroupId + config["message_group_id"] = aws.StringValue(sqsParameters.MessageGroupId) result := []map[string]interface{}{config} return result } @@ -658,9 +656,9 @@ func flattenAwsCloudWatchInputTransformer(inputTransformer *events.InputTransfor config := make(map[string]interface{}) inputPathsMap := make(map[string]string) for k, v := range inputTransformer.InputPathsMap { - inputPathsMap[k] = *v + inputPathsMap[k] = aws.StringValue(v) } - config["input_template"] = *inputTransformer.InputTemplate + config["input_template"] = aws.StringValue(inputTransformer.InputTemplate) config["input_paths"] = inputPathsMap result := []map[string]interface{}{config} diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index 15cbbc6f7fe..3fa2ba9aafe 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -97,7 +97,7 @@ func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) { snsTopicName1 := acctest.RandomWithPrefix("tf-acc-topic") snsTopicName2 := acctest.RandomWithPrefix("tf-acc-topic-second") targetID1 := acctest.RandomWithPrefix("tf-acc-cw-target") - targetID2 := acctest.RandomWithPrefix("tf-acc-cw-target") + targetID2 := acctest.RandomWithPrefix("tf-acc-cw-target-second") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -380,6 +380,31 @@ func TestAccAWSCloudWatchEventTarget_input_transformer(t *testing.T) { }) } +func TestAccAWSCloudWatchEventTarget_disappears(t *testing.T) { + resourceName := "aws_cloudwatch_event_target.test" + + var target events.Target + ruleName := acctest.RandomWithPrefix("tf-acc-cw-event-rule-basic") + snsTopicName1 := acctest.RandomWithPrefix("tf-acc-topic") + targetID1 := acctest.RandomWithPrefix("tf-acc-cw-target") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCloudWatchEventTargetConfig(ruleName, snsTopicName1, targetID1), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudWatchEventTargetExists(resourceName, &target), + testAccCheckResourceDisappears(testAccProvider, resourceAwsCloudWatchEventTarget(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func testAccCheckCloudWatchEventTargetExists(n string, rule *events.Target) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n]