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

b/aws_cloudwatch_event_target: remove default value from ecs_target.propagate_tags #25233

Merged
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
3 changes: 3 additions & 0 deletions .changelog/25233.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
resource/aws_cloudwatch_event_target: The `ecs_target.propagate_tags` attribute now has no default value
```
41 changes: 20 additions & 21 deletions internal/service/events/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ func ResourceTarget() *schema.Resource {
"propagate_tags": {
Type: schema.TypeString,
Optional: true,
Default: eventbridge.PropagateTagsTaskDefinition,
ValidateFunc: validation.StringInSlice(eventbridge.PropagateTags_Values(), false),
},
"tags": tftags.TagsSchema(),
Expand Down Expand Up @@ -768,52 +767,52 @@ func expandTargetRedshiftParameters(config []interface{}) *eventbridge.RedshiftD
return redshiftParameters
}

func expandTargetECSParameters(ctx context.Context, config []interface{}) *eventbridge.EcsParameters {
func expandTargetECSParameters(ctx context.Context, tfList []interface{}) *eventbridge.EcsParameters {
ecsParameters := &eventbridge.EcsParameters{}
for _, c := range config {
param := c.(map[string]interface{})
tags := tftags.New(ctx, param["tags"].(map[string]interface{}))
for _, c := range tfList {
tfMap := c.(map[string]interface{})
tags := tftags.New(ctx, tfMap["tags"].(map[string]interface{}))

if v, ok := param["capacity_provider_strategy"].(*schema.Set); ok && v.Len() > 0 {
if v, ok := tfMap["capacity_provider_strategy"].(*schema.Set); ok && v.Len() > 0 {
ecsParameters.CapacityProviderStrategy = expandTargetCapacityProviderStrategy(v.List())
}

if val, ok := param["group"].(string); ok && val != "" {
ecsParameters.Group = aws.String(val)
if v, ok := tfMap["group"].(string); ok && v != "" {
ecsParameters.Group = aws.String(v)
}

if val, ok := param["launch_type"].(string); ok && val != "" {
ecsParameters.LaunchType = aws.String(val)
if v, ok := tfMap["launch_type"].(string); ok && v != "" {
ecsParameters.LaunchType = aws.String(v)
}

if val, ok := param["network_configuration"]; ok {
ecsParameters.NetworkConfiguration = expandTargetECSParametersNetworkConfiguration(val.([]interface{}))
if v, ok := tfMap["network_configuration"]; ok {
ecsParameters.NetworkConfiguration = expandTargetECSParametersNetworkConfiguration(v.([]interface{}))
}

if val, ok := param["platform_version"].(string); ok && val != "" {
ecsParameters.PlatformVersion = aws.String(val)
if v, ok := tfMap["platform_version"].(string); ok && v != "" {
ecsParameters.PlatformVersion = aws.String(v)
}

if v, ok := param["placement_constraint"].(*schema.Set); ok && v.Len() > 0 {
if v, ok := tfMap["placement_constraint"].(*schema.Set); ok && v.Len() > 0 {
ecsParameters.PlacementConstraints = expandTargetPlacementConstraints(v.List())
}

if v, ok := param["ordered_placement_strategy"]; ok {
if v, ok := tfMap["ordered_placement_strategy"]; ok {
ecsParameters.PlacementStrategy = expandTargetPlacementStrategies(v.([]interface{}))
}

if v, ok := param["propagate_tags"].(string); ok {
if v, ok := tfMap["propagate_tags"].(string); ok && v != "" {
ecsParameters.PropagateTags = aws.String(v)
}

if len(tags) > 0 {
ecsParameters.Tags = Tags(tags.IgnoreAWS())
}

ecsParameters.EnableExecuteCommand = aws.Bool(param["enable_execute_command"].(bool))
ecsParameters.EnableECSManagedTags = aws.Bool(param["enable_ecs_managed_tags"].(bool))
ecsParameters.TaskCount = aws.Int64(int64(param["task_count"].(int)))
ecsParameters.TaskDefinitionArn = aws.String(param["task_definition_arn"].(string))
ecsParameters.EnableExecuteCommand = aws.Bool(tfMap["enable_execute_command"].(bool))
ecsParameters.EnableECSManagedTags = aws.Bool(tfMap["enable_ecs_managed_tags"].(bool))
ecsParameters.TaskCount = aws.Int64(int64(tfMap["task_count"].(int)))
ecsParameters.TaskDefinitionArn = aws.String(tfMap["task_definition_arn"].(string))
}

return ecsParameters
Expand Down
91 changes: 68 additions & 23 deletions internal/service/events/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,12 @@ func TestAccEventsTarget_eventBusARN(t *testing.T) {
t.Skipf("EventBridge Target EventBus ARNs are not supported in %s partition", got)
}

resourceName := "aws_cloudwatch_event_target.test"

var target eventbridge.Target
var v eventbridge.Target
ruleName := sdkacctest.RandomWithPrefix("tf-acc-test-rule")
targetID := sdkacctest.RandomWithPrefix("tf-acc-test-target")
originEventBusName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
destinationEventBusName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_cloudwatch_event_target.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand All @@ -154,7 +153,7 @@ func TestAccEventsTarget_eventBusARN(t *testing.T) {
{
Config: testAccTargetConfig_busARN(ruleName, originEventBusName, targetID, destinationEventBusName, sdkacctest.RandomWithPrefix("tf-acc-test-target"), sdkacctest.RandomWithPrefix("tf-acc-test-target")),
Check: resource.ComposeTestCheckFunc(
testAccCheckTargetExists(ctx, resourceName, &target),
testAccCheckTargetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "rule", ruleName),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "events", regexp.MustCompile(fmt.Sprintf("event-bus/%s", destinationEventBusName))),
acctest.MatchResourceAttrRegionalARN(resourceName, "event_bus_name", "events", regexp.MustCompile(fmt.Sprintf("event-bus/%s", originEventBusName))),
Expand All @@ -173,12 +172,11 @@ func TestAccEventsTarget_eventBusARN(t *testing.T) {

func TestAccEventsTarget_generatedTargetID(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cloudwatch_event_target.test"
snsTopicResourceName := "aws_sns_topic.test"

var v eventbridge.Target
ruleName := sdkacctest.RandomWithPrefix("tf-acc-cw-event-rule-missing-target-id")
snsTopicName := sdkacctest.RandomWithPrefix("tf-acc")
resourceName := "aws_cloudwatch_event_target.test"
snsTopicResourceName := "aws_sns_topic.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand Down Expand Up @@ -245,13 +243,12 @@ func TestAccEventsTarget_RetryPolicy_deadLetter(t *testing.T) {

func TestAccEventsTarget_full(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cloudwatch_event_target.test"
kinesisStreamResourceName := "aws_kinesis_stream.test"
var v eventbridge.Target

ruleName := sdkacctest.RandomWithPrefix("tf-acc-cw-event-rule-full")
ssmDocumentName := sdkacctest.RandomWithPrefix("tf_ssm_Document")
targetID := sdkacctest.RandomWithPrefix("tf-acc-cw-target-full")
resourceName := "aws_cloudwatch_event_target.test"
kinesisStreamResourceName := "aws_kinesis_stream.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand Down Expand Up @@ -282,9 +279,9 @@ func TestAccEventsTarget_full(t *testing.T) {

func TestAccEventsTarget_ssmDocument(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cloudwatch_event_target.test"
var v eventbridge.Target
rName := sdkacctest.RandomWithPrefix("tf_ssm_Document")
resourceName := "aws_cloudwatch_event_target.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand Down Expand Up @@ -314,10 +311,9 @@ func TestAccEventsTarget_ssmDocument(t *testing.T) {

func TestAccEventsTarget_http(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cloudwatch_event_target.test"

var v eventbridge.Target
rName := sdkacctest.RandomWithPrefix("tf_http_target")
resourceName := "aws_cloudwatch_event_target.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand Down Expand Up @@ -351,10 +347,9 @@ func TestAccEventsTarget_http(t *testing.T) {
// https://github.com/hashicorp/terraform-provider-aws/issues/23805
func TestAccEventsTarget_http_params(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cloudwatch_event_target.test"

var v eventbridge.Target
rName := sdkacctest.RandomWithPrefix("tf_http_target")
resourceName := "aws_cloudwatch_event_target.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand Down Expand Up @@ -731,10 +726,10 @@ func TestAccEventsTarget_ecsPlacementStrategy(t *testing.T) {

func TestAccEventsTarget_batch(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cloudwatch_event_target.test"
batchJobDefinitionResourceName := "aws_batch_job_definition.test"
var v eventbridge.Target
rName := sdkacctest.RandomWithPrefix("tf_batch_target")
resourceName := "aws_cloudwatch_event_target.test"
batchJobDefinitionResourceName := "aws_batch_job_definition.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand Down Expand Up @@ -763,9 +758,9 @@ func TestAccEventsTarget_batch(t *testing.T) {

func TestAccEventsTarget_kinesis(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cloudwatch_event_target.test"
var v eventbridge.Target
rName := sdkacctest.RandomWithPrefix("tf_kinesis_target")
resourceName := "aws_cloudwatch_event_target.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand Down Expand Up @@ -880,9 +875,8 @@ func TestAccEventsTarget_Input_transformer(t *testing.T) {

func TestAccEventsTarget_inputTransformerJSONString(t *testing.T) {
ctx := acctest.Context(t)
var target eventbridge.Target
var v eventbridge.Target
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resourceName := "aws_cloudwatch_event_target.test"

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -894,7 +888,7 @@ func TestAccEventsTarget_inputTransformerJSONString(t *testing.T) {
{
Config: testAccTargetConfig_inputTransformerJSONString(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckTargetExists(ctx, resourceName, &target),
testAccCheckTargetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "input_transformer.#", "1"),
resource.TestCheckResourceAttr(resourceName, "input_transformer.0.input_paths.%", "2"),
resource.TestCheckResourceAttr(resourceName, "input_transformer.0.input_paths.instance", "$.detail.instance"),
Expand All @@ -913,7 +907,7 @@ func TestAccEventsTarget_partnerEventBus(t *testing.T) {
t.Skipf("Environment variable %s is not set", key)
}

var target eventbridge.Target
var v eventbridge.Target
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_cloudwatch_event_target.test"
snsTopicResourceName := "aws_sns_topic.test"
Expand All @@ -927,7 +921,7 @@ func TestAccEventsTarget_partnerEventBus(t *testing.T) {
{
Config: testAccTargetConfig_partnerBus(rName, busName),
Check: resource.ComposeTestCheckFunc(
testAccCheckTargetExists(ctx, resourceName, &target),
testAccCheckTargetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "rule", rName),
resource.TestCheckResourceAttr(resourceName, "event_bus_name", busName),
resource.TestCheckResourceAttr(resourceName, "target_id", rName),
Expand All @@ -944,6 +938,38 @@ func TestAccEventsTarget_partnerEventBus(t *testing.T) {
})
}

func TestAccEventsTarget_ecsNoPropagateTags(t *testing.T) {
ctx := acctest.Context(t)
var v eventbridge.Target
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_cloudwatch_event_target.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, eventbridge.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckTargetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccTargetConfig_ecsNoPropagateTags(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckTargetExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "ecs_target.#", "1"),
resource.TestCheckResourceAttr(resourceName, "ecs_target.0.task_count", "1"),
resource.TestCheckResourceAttr(resourceName, "ecs_target.0.launch_type", "FARGATE"),
resource.TestCheckResourceAttr(resourceName, "ecs_target.0.propagate_tags", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName),
ImportStateVerify: true,
},
},
})
}

func testAccCheckTargetExists(ctx context.Context, n string, v *eventbridge.Target) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -2280,3 +2306,22 @@ resource "aws_sns_topic" "test" {
}
`, rName, eventBusName)
}

func testAccTargetConfig_ecsNoPropagateTags(rName string) string {
return acctest.ConfigCompose(testAccTargetConfig_ecsBase(rName), `
resource "aws_cloudwatch_event_target" "test" {
arn = aws_ecs_cluster.test.id
rule = aws_cloudwatch_event_rule.test.id
role_arn = aws_iam_role.test.arn

ecs_target {
task_definition_arn = aws_ecs_task_definition.task.arn
launch_type = "FARGATE"

network_configuration {
subnets = aws_subnet.test[*].id
}
}
}
`)
}
5 changes: 5 additions & 0 deletions website/docs/guides/version-5-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Upgrade topics:
- [Data Source: aws_subnet_ids](#data-source-aws_subnet_ids)
- [Resource: aws_acmpca_certificate_authority](#resource-aws_acmpca_certificate_authority)
- [Resource: aws_ce_anomaly_subscription](#resource-aws_ce_anomaly_subscription)
- [Resource: aws_cloudwatch_event_target](#resource-aws_cloudwatch_event_target)
- [Resource: aws_ec2_client_vpn_endpoint](#resource-aws_ec2_client_vpn_endpoint)
- [Resource: aws_ec2_client_vpn_network_association](#resource-aws_ec2_client_vpn_network_association)

Expand Down Expand Up @@ -94,6 +95,10 @@ The `status` attribute is superfluous and sometimes incorrect. It has been remov

The `threshold` attribute has been removed.

## Resource: aws_cloudwatch_event_target

The `ecs_target.propagate_tags` attribute now has no default value. If no value is specified, the tags are not propagated.

## Resource: aws_ec2_client_vpn_endpoint

The `status` attribute has been removed.
Expand Down