From 8363ab0d243412624d88cd7903718e9fa069c964 Mon Sep 17 00:00:00 2001 From: Paul-Albert Chmilevski Date: Wed, 27 Mar 2019 22:21:49 +0100 Subject: [PATCH] Final changes --- aws/resource_aws_appsync_graphql_api.go | 14 +++++---- aws/resource_aws_appsync_resolver_test.go | 37 ++++++++++++++--------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/aws/resource_aws_appsync_graphql_api.go b/aws/resource_aws_appsync_graphql_api.go index 7bcf17bea4ca..ba10165d96f1 100644 --- a/aws/resource_aws_appsync_graphql_api.go +++ b/aws/resource_aws_appsync_graphql_api.go @@ -166,7 +166,7 @@ func resourceAwsAppsyncGraphqlApiCreate(d *schema.ResourceData, meta interface{} d.SetId(*resp.GraphqlApi.ApiId) - if err := resourceAwsAppsyncSchemaPut(d.Id(), d, conn); err != nil { + if err := resourceAwsAppsyncSchemaPut(d, meta); err != nil { return fmt.Errorf("error creating AppSync GraphQL API (%s) Schema: %s", d.Id(), err) } @@ -240,7 +240,7 @@ func resourceAwsAppsyncGraphqlApiUpdate(d *schema.ResourceData, meta interface{} } if d.HasChange("schema") { - if err := resourceAwsAppsyncSchemaPut(d.Id(), d, conn); err != nil { + if err := resourceAwsAppsyncSchemaPut(d, meta); err != nil { return fmt.Errorf("error updating AppSync GraphQL API (%s) Schema: %s", d.Id(), err) } } @@ -376,10 +376,12 @@ func flattenAppsyncGraphqlApiUserPoolConfig(userPoolConfig *appsync.UserPoolConf return []interface{}{m} } -func resourceAwsAppsyncSchemaPut(apiId string, d *schema.ResourceData, conn *appsync.AppSync) error { +func resourceAwsAppsyncSchemaPut(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).appsyncconn + if v, ok := d.GetOk("schema"); ok { input := &appsync.StartSchemaCreationInput{ - ApiId: aws.String(apiId), + ApiId: aws.String(d.Id()), Definition: ([]byte)(v.(string)), } if _, err := conn.StartSchemaCreation(input); err != nil { @@ -391,7 +393,7 @@ func resourceAwsAppsyncSchemaPut(apiId string, d *schema.ResourceData, conn *app Target: []string{"SUCCESS", appsync.SchemaStatusActive}, // should be only appsync.SchemaStatusActive . I think this is a problem in documentation: https://docs.aws.amazon.com/appsync/latest/APIReference/API_GetSchemaCreationStatus.html Refresh: func() (interface{}, string, error) { result, err := conn.GetSchemaCreationStatus(&appsync.GetSchemaCreationStatusInput{ - ApiId: aws.String(apiId), + ApiId: aws.String(d.Id()), }) if err != nil { return 0, "", err @@ -402,7 +404,7 @@ func resourceAwsAppsyncSchemaPut(apiId string, d *schema.ResourceData, conn *app } if _, err := activeSchemaConfig.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for schema creation status on AppSync API %s: %s", apiId, err) + return fmt.Errorf("Error waiting for schema creation status on AppSync API %s: %s", d.Id(), err) } } diff --git a/aws/resource_aws_appsync_resolver_test.go b/aws/resource_aws_appsync_resolver_test.go index 4dab84a7b1e8..18b4ef350124 100644 --- a/aws/resource_aws_appsync_resolver_test.go +++ b/aws/resource_aws_appsync_resolver_test.go @@ -40,8 +40,7 @@ func TestAccAwsAppsyncResolver_basic(t *testing.T) { } func TestAccAwsAppsyncResolver_DataSource(t *testing.T) { - rName1 := fmt.Sprintf("tfacctest%d", acctest.RandInt()) - rName2 := fmt.Sprintf("tfacctest%d", acctest.RandInt()) + rName := fmt.Sprintf("tfacctest%d", acctest.RandInt()) resourceName := "aws_appsync_resolver.test" resource.ParallelTest(t, resource.TestCase{ @@ -50,24 +49,24 @@ func TestAccAwsAppsyncResolver_DataSource(t *testing.T) { CheckDestroy: testAccCheckAwsAppsyncResolverDestroy, Steps: []resource.TestStep{ { - Config: testAccAppsyncResolver_DataSource(rName1, rName1), + Config: testAccAppsyncResolver_DataSource(rName, "test_ds_1"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsAppsyncResolverExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "data_source", rName1), + resource.TestCheckResourceAttr(resourceName, "data_source", "test_ds_1"), ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAppsyncResolver_DataSource(rName1, rName2), + Config: testAccAppsyncResolver_DataSource(rName, "test_ds_2"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsAppsyncResolverExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "data_source", rName2), + resource.TestCheckResourceAttr(resourceName, "data_source", "test_ds_2"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -312,9 +311,19 @@ schema { EOF } -resource "aws_appsync_datasource" "test" { +resource "aws_appsync_datasource" "test_ds_1" { api_id = "${aws_appsync_graphql_api.test.id}" - name = %q + name = "test_ds_1" + type = "HTTP" + + http_config { + endpoint = "http://example.com" + } +} + +resource "aws_appsync_datasource" "test_ds_2" { + api_id = "${aws_appsync_graphql_api.test.id}" + name = "test_ds_2" type = "HTTP" http_config { @@ -326,7 +335,7 @@ resource "aws_appsync_resolver" "test" { api_id = "${aws_appsync_graphql_api.test.id}" field = "singlePost" type = "Query" - data_source = "${aws_appsync_datasource.test.name}" + data_source = "${aws_appsync_datasource.%s.name}" request_template = <