-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #5774 - Fix the update issues in aws_appsync_datasource #5814
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
181b022
cover the issues in acceptance test
saravanan30erd a2d12e6
fix the update issue in resource appsync
saravanan30erd ef5d4f0
modify accp tests and revert service_role_arn changes
saravanan30erd aab0408
refactor the update func and update tests
saravanan30erd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ func TestAccAwsAppsyncDatasource_lambda(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAwsAppsyncDatasource_update(t *testing.T) { | ||
func TestAccAwsAppsyncDatasource_updateType(t *testing.T) { | ||
rName := acctest.RandString(5) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
|
@@ -89,6 +89,31 @@ func TestAccAwsAppsyncDatasource_update(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAwsAppsyncDatasource_update(t *testing.T) { | ||
rName := acctest.RandString(5) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAppsyncDatasourceConfig_ddb(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAwsAppsyncDatasourceExists("aws_appsync_datasource.test"), | ||
resource.TestCheckResourceAttr("aws_appsync_datasource.test", "description", "appsync datasource version1"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAppsyncDatasourceConfig_update_ddb(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAwsAppsyncDatasourceExists("aws_appsync_datasource.test"), | ||
resource.TestCheckResourceAttr("aws_appsync_datasource.test", "description", "appsync datasource version2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAwsAppsyncDatasourceDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).appsyncconn | ||
for _, rs := range s.RootModule().Resources { | ||
|
@@ -188,6 +213,7 @@ resource "aws_appsync_datasource" "test" { | |
api_id = "${aws_appsync_graphql_api.test.id}" | ||
name = "tf_appsync_%s" | ||
type = "AMAZON_DYNAMODB" | ||
description = "appsync datasource version1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Generally its cleaner to parameterize the test configuration values when changing a single one instead of creating a mostly duplicated new test configuration, e.g. func testAccAppsyncDatasourceConfig_ddb(rName, description string) string {
// ...
description = %q
// ...
`, rName, rName, rName, rName, rName, rName, description)
} |
||
dynamodb_config { | ||
region = "${data.aws_region.current.name}" | ||
table_name = "${aws_dynamodb_table.test.name}" | ||
|
@@ -441,3 +467,78 @@ resource "aws_appsync_datasource" "test" { | |
} | ||
`, rName, rName, rName, rName, rName, rName) | ||
} | ||
|
||
func testAccAppsyncDatasourceConfig_update_ddb(rName string) string { | ||
return fmt.Sprintf(` | ||
data "aws_region" "current" {} | ||
|
||
resource "aws_appsync_graphql_api" "test" { | ||
authentication_type = "API_KEY" | ||
name = "tf_appsync_%s" | ||
} | ||
|
||
resource "aws_dynamodb_table" "test" { | ||
name = "tf-ddb1-%s" | ||
read_capacity = 10 | ||
write_capacity = 10 | ||
hash_key = "UserId" | ||
attribute { | ||
name = "UserId" | ||
type = "S" | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "test" { | ||
name = "tf-role-%s" | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "appsync.amazonaws.com" | ||
}, | ||
"Effect": "Allow" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_role_policy" "test" { | ||
name = "tf-rolepolicy-%s" | ||
role = "${aws_iam_role.test.id}" | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"dynamodb:*" | ||
], | ||
"Effect": "Allow", | ||
"Resource": [ | ||
"${aws_dynamodb_table.test.arn}" | ||
] | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_appsync_datasource" "test" { | ||
api_id = "${aws_appsync_graphql_api.test.id}" | ||
name = "tf_appsync_%s" | ||
type = "AMAZON_DYNAMODB" | ||
description = "appsync datasource version2" | ||
dynamodb_config { | ||
region = "${data.aws_region.current.name}" | ||
table_name = "${aws_dynamodb_table.test.name}" | ||
} | ||
service_role_arn = "${aws_iam_role.test.arn}" | ||
} | ||
`, rName, rName, rName, rName, rName) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this type of change, I'm worried that all parameters must be provided during the update call. We should probably add an acceptance test that has something optional like
description
set, then attempts to update something else likedynamodb_config
, then verifies thatdescription
is still the original value as expected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bflad Reverted the changes which I did for
service_role_arn
attr to provide the proper solution.As you said, looks like all parameters should be provided during the update call and covered this issue with acceptance test
TestAccAwsAppsyncDatasource_update
, working on fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bflad Could you guide me the way how to handle this?
Since all parameters need to be provided in update call, I am thinking to use Get funcs.