From c93fffa27e26b0c7c9d9634c269455b7811c8dbc Mon Sep 17 00:00:00 2001 From: Zoltan Tudlik Date: Thu, 30 May 2024 14:35:04 +0200 Subject: [PATCH] update cloudwatch_event_target website with appsync_target attribute --- .changelog/37773.txt | 2 +- .../r/cloudwatch_event_target.html.markdown | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/.changelog/37773.txt b/.changelog/37773.txt index 33b6c6252afb..f81a4c2b0e63 100644 --- a/.changelog/37773.txt +++ b/.changelog/37773.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_cloudwatch_event_target: Add appsync_target argument +resource/aws_cloudwatch_event_target: Add `appsync_target` argument ``` diff --git a/website/docs/r/cloudwatch_event_target.html.markdown b/website/docs/r/cloudwatch_event_target.html.markdown index 82d2cf9b2468..b0b069ec5c73 100644 --- a/website/docs/r/cloudwatch_event_target.html.markdown +++ b/website/docs/r/cloudwatch_event_target.html.markdown @@ -448,6 +448,101 @@ resource "aws_cloudwatch_event_target" "example" { } ``` +### AppSync Usage + +```terraform +resource "aws_cloudwatch_event_rule" "invoke_appsync_mutation" { + name = "invoke-appsync-mutation" + description = "schedule_batch_test" + schedule_expression = "rate(5 minutes)" +} + +resource "aws_cloudwatch_event_target" "invoke_appsync_mutation" { + arn = replace(aws_appsync_graphql_api.graphql-api.arn, "apis", "endpoints/graphql-api") + rule = aws_cloudwatch_event_rule.invoke_appsync_mutation.id + role_arn = aws_iam_role.appsync_mutation_role.arn + + input_transformer { + input_paths = { + input = "$.detail.input" + } + + input_template = < + } + EOF + } + + appsync_target { + graphql_operation = "mutation TestMutation($input:MutationInput!){testMutation(input: $input) {test}}" + } +} + +resource "aws_iam_role" "appsync_mutation_role" { + name = "appsync-mutation-role" + assume_role_policy = data.aws_iam_policy_document.appsync_mutation_role_trust.json +} + +data "aws_iam_policy_document" "appsync_mutation_role_trust" { + statement { + actions = ["sts:AssumeRole"] + + principals { + type = "Service" + identifiers = ["events.amazonaws.com"] + } + } +} + +data "aws_iam_policy_document" "appsync_mutation_role_policy_document" { + statement { + actions = ["appsync:GraphQL"] + effect = "Allow" + resources = [ + aws_appsync_graphql_api.graphql-api.arn + ] + } +} + +resource "aws_iam_policy" "appsync_mutation_role_policy" { + name = "appsync-mutation-role-policy" + policy = data.aws_iam_policy_document.appsync_mutation_role_policy_document.json +} + +resource "aws_iam_role_policy_attachment" "appsync_mutation_role_attachment" { + policy_arn = aws_iam_policy.appsync_mutation_role_policy.arn + role = aws_iam_role.appsync_mutation_role.name +} + +resource "aws_appsync_graphql_api" "graphql-api" { + name = "api" + authentication_type = "AWS_IAM" + schema = < **Note:** In order to be able to have your AWS Lambda function or @@ -481,6 +576,7 @@ 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 @@ -583,6 +679,10 @@ For more information, see [Task Networking](https://docs.aws.amazon.com/AmazonEC * `name` - (Required) Name of parameter to start execution of a SageMaker Model Building Pipeline. * `value` - (Required) Value of parameter to start execution of a SageMaker Model Building Pipeline. +### appsync_target + +* `graphql_operation` - (Optional) Contains the GraphQL mutation to be parsed and executed. + ## Attribute Reference This resource exports no additional attributes.