Skip to content

Commit

Permalink
Cosmetics.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Oct 15, 2024
1 parent 47bb1c4 commit f9f7ac0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .changelog/37773.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```release-note:enhancement
resource/aws_cloudwatch_event_target: Add `appsync_target` argument
resource/aws_cloudwatch_event_target: Add `appsync_target` configuration block
```
2 changes: 1 addition & 1 deletion .changelog/37799.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```release-note:enhancement
resource/aws_dynamodb_table: Add `on_demand_throughput` and `global_secondary_index.on_demand_throughput` arguments
resource/aws_dynamodb_table: Add `on_demand_throughput` and `global_secondary_index.on_demand_throughput` arguments
```
57 changes: 29 additions & 28 deletions internal/service/events/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ func resourceTarget() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"appsync_target": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"graphql_operation": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 1048576)),
},
},
},
},
names.AttrARN: {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -489,20 +503,6 @@ func resourceTarget() *schema.Resource {
ForceNew: true,
ValidateFunc: validateTargetID,
},
"appsync_target": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"graphql_operation": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 1048576)),
},
},
},
},
},
}
}
Expand Down Expand Up @@ -636,7 +636,7 @@ func resourceTargetRead(ctx context.Context, d *schema.ResourceData, meta interf
}

if target.AppSyncParameters != nil {
if err := d.Set("appsync_target", flattenTargetAppSyncParameters(target.AppSyncParameters)); err != nil {
if err := d.Set("appsync_target", flattenAppSyncParameters(target.AppSyncParameters)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting appsync_target: %s", err)
}
}
Expand Down Expand Up @@ -892,7 +892,7 @@ func expandPutTargetsInput(ctx context.Context, d *schema.ResourceData) *eventbr
}

if v, ok := d.GetOk("appsync_target"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
target.AppSyncParameters = expandTargetAppSyncParameters(v.([]interface{}))
target.AppSyncParameters = expandAppSyncParameters(v.([]interface{}))
}

input := &eventbridge.PutTargetsInput{
Expand Down Expand Up @@ -1509,21 +1509,22 @@ func flattenTargetCapacityProviderStrategy(cps []types.CapacityProviderStrategyI
return results
}

func flattenTargetAppSyncParameters(appSyncParameters *types.AppSyncParameters) []map[string]interface{} {
config := make(map[string]interface{})
config["graphql_operation"] = aws.ToString(appSyncParameters.GraphQLOperation)
result := []map[string]interface{}{config}
return result
func flattenAppSyncParameters(apiObject *types.AppSyncParameters) []map[string]interface{} {
tfMap := make(map[string]interface{})
tfMap["graphql_operation"] = aws.ToString(apiObject.GraphQLOperation)

return []map[string]interface{}{tfMap}
}

func expandTargetAppSyncParameters(config []interface{}) *types.AppSyncParameters {
appSyncParameters := &types.AppSyncParameters{}
for _, c := range config {
param := c.(map[string]interface{})
if v, ok := param["graphql_operation"].(string); ok && v != "" {
appSyncParameters.GraphQLOperation = aws.String(v)
func expandAppSyncParameters(tfList []interface{}) *types.AppSyncParameters {
apiObject := &types.AppSyncParameters{}

for _, tfMapRaw := range tfList {
tfMap := tfMapRaw.(map[string]interface{})
if v, ok := tfMap["graphql_operation"].(string); ok && v != "" {
apiObject.GraphQLOperation = aws.String(v)
}
}

return appSyncParameters
return apiObject
}
2 changes: 1 addition & 1 deletion website/docs/r/cloudwatch_event_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ The following arguments are required:

The following arguments are optional:

* `appsync_target` - (Optional) Parameters used when you are using the rule to invoke an AppSync GraphQL API mutation. Documented below. A maximum of 1 are allowed.
* `batch_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon Batch Job. Documented below. A maximum of 1 are allowed.
* `dead_letter_config` - (Optional) Parameters used when you are providing a dead letter config. Documented below. A maximum of 1 are allowed.
* `ecs_target` - (Optional) Parameters used when you are using the rule to invoke Amazon ECS Task. Documented below. A maximum of 1 are allowed.
Expand All @@ -576,7 +577,6 @@ The following arguments are optional:
* `sagemaker_pipeline_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon SageMaker Pipeline. Documented below. A maximum of 1 are allowed.
* `sqs_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon SQS Queue. Documented below. A maximum of 1 are allowed.
* `target_id` - (Optional) The unique target assignment ID. If missing, will generate a random, unique id.
* `appsync_target` - (Optional) Parameters used when you are using the rule to invoke an AppSync GraphQL API mutation. Documented below. A maximum of 1 are allowed.

### batch_target

Expand Down

0 comments on commit f9f7ac0

Please sign in to comment.