From 416cd088b1a5d0292dffa064fd1d388d41f4918d Mon Sep 17 00:00:00 2001 From: Alexander Chernov Date: Wed, 30 Dec 2020 15:03:53 +0000 Subject: [PATCH] feat: added additional error detail to the graphql schema creation. See [16814] Signed-off-by: Alexander Chernov --- aws/resource_aws_appsync_graphql_api.go | 3 +++ aws/resource_aws_appsync_graphql_api_test.go | 26 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/aws/resource_aws_appsync_graphql_api.go b/aws/resource_aws_appsync_graphql_api.go index af4988538c2..1a8069fa113 100644 --- a/aws/resource_aws_appsync_graphql_api.go +++ b/aws/resource_aws_appsync_graphql_api.go @@ -598,6 +598,9 @@ func resourceAwsAppsyncSchemaPut(d *schema.ResourceData, meta interface{}) error if err != nil { return 0, "", err } + if *result.Status == "FAILED" { + return result, *result.Status, fmt.Errorf("%s", *result.Details) + } return result, *result.Status, nil }, Timeout: d.Timeout(schema.TimeoutCreate), diff --git a/aws/resource_aws_appsync_graphql_api_test.go b/aws/resource_aws_appsync_graphql_api_test.go index d3fc44785f3..3fd392acb14 100644 --- a/aws/resource_aws_appsync_graphql_api_test.go +++ b/aws/resource_aws_appsync_graphql_api_test.go @@ -166,6 +166,22 @@ func TestAccAWSAppsyncGraphqlApi_Schema(t *testing.T) { }) } +func TestAccAWSAppsyncGraphqlApi_Schema_Error(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(appsync.EndpointsID, t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAppsyncGraphqlApiConfig_Schema_Invalid(rName), + ExpectError: regexp.MustCompile("The field type 'PostV2' is not present when resolving type 'Query'"), + }, + }, + }) +} + func TestAccAWSAppsyncGraphqlApi_AuthenticationType(t *testing.T) { var api1, api2 appsync.GraphqlApi rName := acctest.RandomWithPrefix("tf-acc-test") @@ -1205,6 +1221,16 @@ resource "aws_appsync_graphql_api" "test" { `, rName) } +func testAccAppsyncGraphqlApiConfig_Schema_Invalid(rName string) string { + return fmt.Sprintf(` +resource "aws_appsync_graphql_api" "test" { + authentication_type = "API_KEY" + name = %q + schema = "type Mutation {\n\tputPost(id: ID!, title: String!): Post\n}\n\ntype Post {\n\tid: ID!\n\ttitle: String!\n}\n\ntype Query {\n\tsinglePost(id: ID!): PostV2\n}\n\nschema {\n\tquery: Query\n\tmutation: Mutation\n\n}\n" +} +`, rName) +} + func testAccAppsyncGraphqlApiConfig_SchemaUpdate(rName string) string { return fmt.Sprintf(` resource "aws_appsync_graphql_api" "test" {