Skip to content

Commit

Permalink
Merge pull request #8675 from terraform-providers/t-appsync-precheck
Browse files Browse the repository at this point in the history
service/appsync: Various minor fixes
  • Loading branch information
bflad authored May 24, 2019
2 parents 0574520 + b01bfd6 commit 72ba3a0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 52 deletions.
6 changes: 3 additions & 3 deletions aws/resource_aws_appsync_api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccAWSAppsyncApiKey_basic(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncApiKeyDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestAccAWSAppsyncApiKey_Description(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncApiKeyDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestAccAWSAppsyncApiKey_Expires(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncApiKeyDestroy,
Steps: []resource.TestStep{
Expand Down
26 changes: 13 additions & 13 deletions aws/resource_aws_appsync_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccAwsAppsyncDatasource_basic(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestAccAwsAppsyncDatasource_Description(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestAccAwsAppsyncDatasource_DynamoDBConfig_Region(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestAccAwsAppsyncDatasource_DynamoDBConfig_UseCallerCredentials(t *testing.
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestAccAwsAppsyncDatasource_ElasticsearchConfig_Region(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestAccAwsAppsyncDatasource_HTTPConfig_Endpoint(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestAccAwsAppsyncDatasource_Type(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestAccAwsAppsyncDatasource_Type_DynamoDB(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestAccAwsAppsyncDatasource_Type_Elasticsearch(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestAccAwsAppsyncDatasource_Type_HTTP(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestAccAwsAppsyncDatasource_Type_Lambda(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestAccAwsAppsyncDatasource_Type_None(t *testing.T) {
resourceName := "aws_appsync_datasource.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -577,7 +577,7 @@ resource "aws_lambda_function" "test" {
function_name = %q
handler = "exports.test"
role = "${aws_iam_role.lambda.arn}"
runtime = "nodejs6.10"
runtime = "nodejs8.10"
}
resource "aws_iam_role" "test" {
Expand Down
28 changes: 16 additions & 12 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{}

resp, err := conn.CreateGraphqlApi(input)
if err != nil {
return fmt.Errorf("error creating AppSync GraphQL API: %d", err)
return fmt.Errorf("error creating AppSync GraphQL API: %s", err)
}

d.SetId(*resp.GraphqlApi.ApiId)
Expand All @@ -186,13 +186,15 @@ func resourceAwsAppsyncGraphqlApiRead(d *schema.ResourceData, meta interface{})
}

resp, err := conn.GetGraphqlApi(input)

if isAWSErr(err, appsync.ErrCodeNotFoundException, "") {
log.Printf("[WARN] No such entity found for Appsync Graphql API (%s)", d.Id())
d.SetId("")
return nil
}

if err != nil {
if isAWSErr(err, appsync.ErrCodeNotFoundException, "") {
log.Printf("[WARN] No such entity found for Appsync Graphql API (%s)", d.Id())
d.SetId("")
return nil
}
return err
return fmt.Errorf("error getting AppSync GraphQL API (%s): %s", d.Id(), err)
}

d.Set("arn", resp.GraphqlApi.Arn)
Expand Down Expand Up @@ -250,7 +252,7 @@ func resourceAwsAppsyncGraphqlApiUpdate(d *schema.ResourceData, meta interface{}

_, err := conn.UpdateGraphqlApi(input)
if err != nil {
return err
return fmt.Errorf("error updating AppSync GraphQL API (%s): %s", d.Id(), err)
}

if d.HasChange("schema") {
Expand All @@ -269,11 +271,13 @@ func resourceAwsAppsyncGraphqlApiDelete(d *schema.ResourceData, meta interface{}
ApiId: aws.String(d.Id()),
}
_, err := conn.DeleteGraphqlApi(input)

if isAWSErr(err, appsync.ErrCodeNotFoundException, "") {
return nil
}

if err != nil {
if isAWSErr(err, appsync.ErrCodeNotFoundException, "") {
return nil
}
return err
return fmt.Errorf("error deleting AppSync GraphQL API (%s): %s", d.Id(), err)
}

return nil
Expand Down
52 changes: 34 additions & 18 deletions aws/resource_aws_appsync_graphql_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestAccAWSAppsyncGraphqlApi_basic(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestAccAWSAppsyncGraphqlApi_disappears(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand All @@ -126,7 +126,7 @@ func TestAccAWSAppsyncGraphqlApi_Schema(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestAccAWSAppsyncGraphqlApi_AuthenticationType(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestAccAWSAppsyncGraphqlApi_AuthenticationType_APIKey(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestAccAWSAppsyncGraphqlApi_AuthenticationType_AWSIAM(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -259,7 +259,7 @@ func TestAccAWSAppsyncGraphqlApi_AuthenticationType_AmazonCognitoUserPools(t *te
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestAccAWSAppsyncGraphqlApi_AuthenticationType_OpenIDConnect(t *testing.T)
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestAccAWSAppsyncGraphqlApi_LogConfig(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestAccAWSAppsyncGraphqlApi_LogConfig_FieldLogLevel(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_AuthTTL(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_ClientID(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -471,7 +471,7 @@ func TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_IatTTL(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_Issuer(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestAccAWSAppsyncGraphqlApi_Name(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -577,7 +577,7 @@ func TestAccAWSAppsyncGraphqlApi_UserPoolConfig_AwsRegion(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -619,7 +619,7 @@ func TestAccAWSAppsyncGraphqlApi_UserPoolConfig_DefaultAction(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -660,7 +660,7 @@ func TestAccAWSAppsyncGraphqlApi_Tags(t *testing.T) {
resourceName := "aws_appsync_graphql_api.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAppSync(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -779,6 +779,22 @@ func testAccCheckAwsAppsyncTypeExists(name, typeName string) resource.TestCheckF
}
}

func testAccPreCheckAWSAppSync(t *testing.T) {
conn := testAccProvider.Meta().(*AWSClient).appsyncconn

input := &appsync.ListGraphqlApisInput{}

_, err := conn.ListGraphqlApis(input)

if testAccPreCheckSkipError(err) {
t.Skipf("skipping acceptance testing: %s", err)
}

if err != nil {
t.Fatalf("unexpected PreCheck error: %s", err)
}
}

func testAccAppsyncGraphqlApiConfig_AuthenticationType(rName, authenticationType string) string {
return fmt.Sprintf(`
resource "aws_appsync_graphql_api" "test" {
Expand Down
Loading

0 comments on commit 72ba3a0

Please sign in to comment.