-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Destroy aws_ram_resource_share_accepter from member account when share contains some resource types #19718
Destroy aws_ram_resource_share_accepter from member account when share contains some resource types #19718
Conversation
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.
Welcome @kbalk 👋
It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.
Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.
Thanks again, and welcome to the community! 😃
I've made the source code change and modified the unit test for this issue, but the unit test will give the error:
A unit test has the ability to check that the "resource of interest" (in this case aws_ram_resource_share_accepter) has been destroyed, but I can't squelch the error message related to the destruction of other related resources. There's an I can silence the above error in
Basically, I'm not sure how to work around the destroy error. |
@shuheiktgw I was wondering about a change you made in your commit of April 27, 2021 to Fix aws_ram_resource_share_accepter eventual consistency problems. One of those changes involved the creation of the function In my test case for this PR, I'm deleting aws_ram_resource_share_accepter with associated resources, but sometimes |
If I set the test option "parallel" to 20 instead of 1, the unit test will pass. If I set TF_LOG, the unit test will pass. |
Hmm, looking like there is some kind of race condition in the
In order to separate that race condition from the issue that this patch is fixing, recommend sharing a Codebuild job in the test instead. Here is an updated config that is working for me when I exercise this patch: provider "aws" {
profile = "resource-member"
}
provider "aws" {
alias = "owner"
profile = "resource-owner"
}
resource "aws_ram_resource_share_accepter" "member" {
share_arn = aws_ram_principal_association.invite.resource_share_arn
}
resource "aws_ram_principal_association" "invite" {
provider = aws.owner
principal = data.aws_caller_identity.member.account_id
resource_share_arn = aws_ram_resource_share.owner.arn
}
resource "aws_ram_resource_share" "owner" {
provider = aws.owner
name = local.name
allow_external_principals = true
}
resource "aws_ram_resource_association" "codebuild" {
provider = aws.owner
resource_arn = aws_codebuild_project.this.arn
resource_share_arn = aws_ram_resource_share.owner.arn
}
resource "aws_codebuild_project" "this" {
provider = aws.owner
name = local.name
service_role = aws_iam_role.codebuild.arn
source {
type = "NO_SOURCE"
buildspec = <<-BUILDSPEC
version: 0.2
phases: {}
BUILDSPEC
}
artifacts {
type = "NO_ARTIFACTS"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/standard:5.0"
type = "LINUX_CONTAINER"
}
}
resource "aws_iam_role" "codebuild" {
provider = aws.owner
name = local.name
assume_role_policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "codebuild.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_role_policy" "codebuild" {
provider = aws.owner
role = aws_iam_role.codebuild.name
policy = <<-POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": [
"*"
],
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
}
]
}
POLICY
}
resource "random_string" "this" {
length = 6
upper = false
special = false
number = false
}
locals {
name = "tf-test-resource-share-${random_string.this.result}"
}
data "aws_caller_identity" "member" {}
output "ram_share_arn" {
value = aws_ram_resource_share.owner.arn
} |
Alternatively, putting a simple 10s sleep on destroy between the assocation and query log config appears to stabilize the test when sharing the query log config: provider "aws" {
profile = "resource-member"
}
provider "aws" {
alias = "owner"
profile = "resource-owner"
}
resource "aws_ram_resource_share_accepter" "member" {
share_arn = aws_ram_principal_association.invite.resource_share_arn
}
resource "aws_ram_principal_association" "invite" {
provider = aws.owner
principal = data.aws_caller_identity.member.account_id
resource_share_arn = aws_ram_resource_share.owner.arn
}
resource "aws_ram_resource_share" "owner" {
provider = aws.owner
name = local.name
allow_external_principals = true
}
resource "aws_ram_resource_association" "query_log" {
provider = aws.owner
resource_arn = time_sleep.wait.triggers.query_log_config_arn
resource_share_arn = aws_ram_resource_share.owner.arn
}
resource "time_sleep" "wait" {
destroy_duration = "10s"
triggers = {
query_log_config_arn = aws_route53_resolver_query_log_config.this.arn
}
}
resource "aws_route53_resolver_query_log_config" "this" {
provider = aws.owner
name = local.name
destination_arn = aws_s3_bucket.query_log.arn
}
resource "aws_s3_bucket" "query_log" {
provider = aws.owner
force_destroy = true
}
resource "random_string" "this" {
length = 6
upper = false
special = false
number = false
}
locals {
name = "tf-test-resource-share-${random_string.this.result}"
}
data "aws_caller_identity" "member" {}
output "ram_share_arn" {
value = aws_ram_resource_share.owner.arn
} |
Replaced the unit test that demonstrates the timing problem with the destruction of RAM shared resources and instead used a unit test that is not affected by the timing problem. |
I ran the test in a loop to try to confirm this test is not impacted by eventual consistency issues:
|
3fe840f
to
db357b0
Compare
@kbalk Thanks for your contribution! I made a few minor tweaks. Hopefully we'll get this merged today. |
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.
Looks good! 🎉
Check my minor changes to see some preferred ways.
Output from acceptance tests:
--- PASS: TestAccAwsRamResourceShareAccepter_basic (89.59s)
--- PASS: TestAccAwsRamResourceShareAccepter_resourceAssociation (97.37s)
--- PASS: TestAccAwsRamResourceShareAccepter_disappears (264.03s)
This functionality has been released in v3.49.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Closes #19319
Output from acceptance testing:
I just realized that the comments associated with this PR are probably confusing: The original unit test submitted with this code change brought out a timing issue. As this timing issue was not the result of the code change, a different unit test was created to demonstrate that the code change worked. The timing issue still needs to be addressed and Terraform will need to decide how they want to handle it. The original unit test can be retrieved from the commits and the comments provide more information on the timing problem.