Skip to content

Commit

Permalink
Merge branch 'support_direct_resolver' of ssh://github.com/shuheiktgw…
Browse files Browse the repository at this point in the history
…/terraform-provider-aws into shuheiktgw-support_direct_resolver
  • Loading branch information
bflad committed Apr 29, 2021
2 parents 8a48195 + ef8bae6 commit 0679f4c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 10 deletions.
22 changes: 14 additions & 8 deletions aws/resource_aws_appsync_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func resourceAwsAppsyncResolver() *schema.Resource {
},
"request_template": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"response_template": {
Type: schema.TypeString,
Required: true, // documentation bug, the api returns 400 if this is not specified.
Optional: true,
},
"kind": {
Type: schema.TypeString,
Expand Down Expand Up @@ -110,12 +110,10 @@ func resourceAwsAppsyncResolverCreate(d *schema.ResourceData, meta interface{})
conn := meta.(*AWSClient).appsyncconn

input := &appsync.CreateResolverInput{
ApiId: aws.String(d.Get("api_id").(string)),
TypeName: aws.String(d.Get("type").(string)),
FieldName: aws.String(d.Get("field").(string)),
RequestMappingTemplate: aws.String(d.Get("request_template").(string)),
ResponseMappingTemplate: aws.String(d.Get("response_template").(string)),
Kind: aws.String(d.Get("kind").(string)),
ApiId: aws.String(d.Get("api_id").(string)),
TypeName: aws.String(d.Get("type").(string)),
FieldName: aws.String(d.Get("field").(string)),
Kind: aws.String(d.Get("kind").(string)),
}

if v, ok := d.GetOk("data_source"); ok {
Expand All @@ -129,6 +127,14 @@ func resourceAwsAppsyncResolverCreate(d *schema.ResourceData, meta interface{})
}
}

if v, ok := d.GetOk("request_template"); ok {
input.RequestMappingTemplate = aws.String(v.(string))
}

if v, ok := d.GetOk("response_template"); ok {
input.ResponseMappingTemplate = aws.String(v.(string))
}

if v, ok := d.GetOk("caching_config"); ok {
input.CachingConfig = expandAppsyncResolverCachingConfig(v.([]interface{}))
}
Expand Down
74 changes: 74 additions & 0 deletions aws/resource_aws_appsync_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@ func TestAccAwsAppsyncResolver_DataSource(t *testing.T) {
})
}

func TestAccAwsAppsyncResolver_DataSource_lambda(t *testing.T) {
var resolver appsync.Resolver
rName := fmt.Sprintf("tfacctest%d", acctest.RandInt())
resourceName := "aws_appsync_resolver.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
ErrorCheck: testAccErrorCheck(t, appsync.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncResolverDestroy,
Steps: []resource.TestStep{
{
Config: testAccAppsyncResolver_DataSource_lambda(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsAppsyncResolverExists(resourceName, &resolver),
resource.TestCheckResourceAttr(resourceName, "data_source", rName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAwsAppsyncResolver_RequestTemplate(t *testing.T) {
var resolver1, resolver2 appsync.Resolver
rName := fmt.Sprintf("tfacctest%d", acctest.RandInt())
Expand Down Expand Up @@ -463,6 +490,53 @@ EOF
`, rName, dataSource)
}

func testAccAppsyncResolver_DataSource_lambda(rName string) string {
return testAccAppsyncDatasourceConfig_base_Lambda(rName) + fmt.Sprintf(`
resource "aws_appsync_graphql_api" "test" {
authentication_type = "API_KEY"
name = %q
schema = <<EOF
type Mutation {
putPost(id: ID!, title: String!): Post
}
type Post {
id: ID!
title: String!
}
type Query {
singlePost(id: ID!): Post
}
schema {
query: Query
mutation: Mutation
}
EOF
}
resource "aws_appsync_datasource" "test" {
api_id = "${aws_appsync_graphql_api.test.id}"
name = %q
service_role_arn = "${aws_iam_role.test.arn}"
type = "AWS_LAMBDA"
lambda_config {
function_arn = "${aws_lambda_function.test.arn}"
}
}
resource "aws_appsync_resolver" "test" {
api_id = aws_appsync_graphql_api.test.id
field = "singlePost"
type = "Query"
data_source = aws_appsync_datasource.test.name
}
`, rName, rName)
}

func testAccAppsyncResolver_RequestTemplate(rName, resourcePath string) string {
return fmt.Sprintf(`
resource "aws_appsync_graphql_api" "test" {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/appsync_resolver.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ The following arguments are supported:
* `api_id` - (Required) The API ID for the GraphQL API.
* `type` - (Required) The type name from the schema defined in the GraphQL API.
* `field` - (Required) The field name from the schema defined in the GraphQL API.
* `request_template` - (Required) The request mapping template for UNIT resolver or 'before mapping template' for PIPELINE resolver.
* `response_template` - (Required) The response mapping template for UNIT resolver or 'after mapping template' for PIPELINE resolver.
* `request_template` - (Optional) The request mapping template for UNIT resolver or 'before mapping template' for PIPELINE resolver. Required for non-Lambda resolvers.
* `response_template` - (Optional) The response mapping template for UNIT resolver or 'after mapping template' for PIPELINE resolver. Required for non-Lambda resolvers.
* `data_source` - (Optional) The DataSource name.
* `kind` - (Optional) The resolver type. Valid values are `UNIT` and `PIPELINE`.
* `pipeline_config` - (Optional) The PipelineConfig.
Expand Down

0 comments on commit 0679f4c

Please sign in to comment.