-
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
add aws_dataexchange_event_action #40552
base: main
Are you sure you want to change the base?
add aws_dataexchange_event_action #40552
Conversation
Community NoteVoting for Prioritization
For Submitters
|
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.
Thanks for your submission!
I added some comments with suggestions on how to adopt some standard provider conventions. A couple other points not specific to the existing code:
- You'll need to run
make gen
to get the service package generator to pick up the presence of this new resource. I suspect the existing acceptance tests are not actually running, because this resource is not currently registered correctly and that should be failing any test configuration which references it. https://hashicorp.github.io/terraform-provider-aws/add-a-new-resource/#register-resource-to-the-provider - The registry documentation for this resource is missing and will need to be included as part of this PR (if you used
skaff
to generate this resource it should have also generated a corresponding file in thewebsite
subfolder). https://hashicorp.github.io/terraform-provider-aws/add-a-new-resource/#create-documentation-for-the-resource - A
new-resource
changelog entry should also be included. https://hashicorp.github.io/terraform-provider-aws/changelog-process/#new-resource - The source code for the
aws_dataexchange_job
resource is also included in this PR. That can be removed in favor of add aws_dataexchange_job #40551 .
bucketName := strconv.Itoa(int(time.Now().UnixNano())) | ||
|
||
if _, okAcc := os.LookupEnv("TF_ACC"); !okAcc { | ||
t.Skipf("TF_ACC must be set") | ||
} | ||
|
||
cfg, err := config.LoadDefaultConfig(ctx) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
stsConn := sts.NewFromConfig(cfg) | ||
identity, err := stsConn.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{}) | ||
|
||
dataSetId, err := helperAccEventActionGetReceivedDataSet(ctx, awstypes.AssetTypeS3Snapshot) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if dataSetId == "" { | ||
return | ||
} |
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.
I'm having trouble identifying the purpose of this setup - is there a way this can be incorporated into the test configuration itself, rather than manual steps outside the scope of the test run?
resource "aws_s3_bucket" "test" { | ||
bucket = "%s" | ||
force_destroy = true | ||
} | ||
|
||
resource "aws_s3_bucket_policy" "test" { | ||
bucket = aws_s3_bucket.test.id | ||
policy = data.aws_iam_policy_document.test.json | ||
} | ||
|
||
data "aws_iam_policy_document" "test" { | ||
statement { | ||
principals { | ||
type = "Service" | ||
identifiers = ["dataexchange.amazonaws.com"] | ||
} | ||
|
||
actions = [ | ||
"s3:PutObject", | ||
"s3:PutObjectAcl", | ||
] | ||
|
||
resources = [ | ||
"${aws_s3_bucket.test.arn}/*", | ||
] | ||
|
||
condition { | ||
test = "StringEquals" | ||
variable = "aws:SourceAccount" | ||
|
||
values = [ | ||
"%s" | ||
] | ||
} | ||
} | ||
} |
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.
Configuration shared across tests can be moved into its own helper function (e.g. testAccEventActionConfigBase
) and then merged with test-specific config via the acctest.ConfigCompose
helper function.
if _, okAcc := os.LookupEnv("TF_ACC"); !okAcc { | ||
t.Skipf("TF_ACC must be set") | ||
} |
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.
This is already implicitly handled and does not need to be included in each test body.
input, diags := r.buildCreateInput(ctx, data) | ||
if diags.HasError() { | ||
resp.Diagnostics.Append(diags...) | ||
return | ||
} |
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.
Rather than custom methods to construct the input, AutoFlex should be used. At a high level, this process uses reflection to convert between the Terraform and AWS data structures. More information available here:
return | ||
} | ||
|
||
resp.Diagnostics.Append(r.buildModelFromOutput(ctx, out, &state)...) |
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.
Similar to the comment about, this should use the AutoFlex Flatten
function rather than custom logic to translate between AWS and Terraform data structures.
_, err := conn.DeleteEventAction(ctx, &dataexchange.DeleteEventActionInput{ | ||
EventActionId: state.ID.ValueStringPointer(), | ||
}) |
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.
In most cases, the Update method should not directly call a Delete API. Instead, the attribute that triggers a replacement should be marked with a RequiresReplace()
plan modifier.
https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification#requiresreplace
_, err := conn.GetEventAction(ctx, &dataexchange.GetEventActionInput{ | ||
EventActionId: aws.String(rs.Primary.ID), | ||
}) |
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.
The finder function findEventActionByID
can be used here in place of the call directly to the Get API. The same is true of the check for existence below.
Description
This PR adds a resource for aws_dataexchange_event_action
Relations
Closes #40418
Output from Acceptance Testing