Skip to content

Commit

Permalink
Final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Albert Chmilevski committed Mar 27, 2019
1 parent 15e2e23 commit 8363ab0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
14 changes: 8 additions & 6 deletions aws/resource_aws_appsync_graphql_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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)
}
}

Expand Down
37 changes: 23 additions & 14 deletions aws/resource_aws_appsync_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
},
},
})
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 = <<EOF
{
"version": "2018-05-29",
Expand Down

0 comments on commit 8363ab0

Please sign in to comment.