Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

TSKnuhtsen
Copy link

Description

This PR adds a resource for aws_dataexchange_event_action

Relations

Closes #40418

Output from Acceptance Testing

thyge@u5f9f1f071ee45a:~/development/clone/terraform-provider-aws$ make testacc TESTS=TestAccDataExchangeEventAction_* PKG=dataexchange
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/dataexchange/... -v -count 1 -parallel 20 -run='TestAccDataExchangeEventAction_*'  -timeout 360m
2024/12/12 20:29:23 Initializing Terraform AWS Provider...
=== RUN   TestAccDataExchangeEventAction_basic
--- PASS: TestAccDataExchangeEventAction_basic (0.67s)
=== RUN   TestAccDataExchangeEventAction_update
--- PASS: TestAccDataExchangeEventAction_update (0.61s)
=== RUN   TestAccDataExchangeEventAction_disappears
--- PASS: TestAccDataExchangeEventAction_disappears (0.66s)
=== RUN   TestAccDataExchangeEventAction_keyPattern
--- PASS: TestAccDataExchangeEventAction_keyPattern (0.62s)
=== RUN   TestAccDataExchangeEventAction_encryption
--- PASS: TestAccDataExchangeEventAction_encryption (0.60s)
=== RUN   TestAccDataExchangeEventAction_kmsKeyEncryption
--- PASS: TestAccDataExchangeEventAction_kmsKeyEncryption (0.64s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/dataexchange	4.067s
...

@TSKnuhtsen TSKnuhtsen requested a review from a team as a code owner December 13, 2024 03:36
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/dataexchange Issues and PRs that pertain to the dataexchange service. needs-triage Waiting for first response or review from a maintainer. labels Dec 13, 2024
@justinretzolk justinretzolk added new-resource Introduces a new resource. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 13, 2024
Copy link
Member

@jar-b jar-b left a 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:

Comment on lines +41 to +61
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
}
Copy link
Member

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?

Comment on lines +409 to +444
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"
]
}
}
}
Copy link
Member

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.

Comment on lines +43 to +45
if _, okAcc := os.LookupEnv("TF_ACC"); !okAcc {
t.Skipf("TF_ACC must be set")
}
Copy link
Member

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.

Comment on lines 107 to 111
input, diags := r.buildCreateInput(ctx, data)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
return
}
Copy link
Member

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:

https://hashicorp.github.io/terraform-provider-aws/data-handling-and-conversion/#autoflex-for-terraform-plugin-framework-preferred

return
}

resp.Diagnostics.Append(r.buildModelFromOutput(ctx, out, &state)...)
Copy link
Member

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.

Comment on lines 258 to 260
_, err := conn.DeleteEventAction(ctx, &dataexchange.DeleteEventActionInput{
EventActionId: state.ID.ValueStringPointer(),
})
Copy link
Member

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

internal/service/dataexchange/event_action_test.go Outdated Show resolved Hide resolved
internal/service/dataexchange/event_action_test.go Outdated Show resolved Hide resolved
Comment on lines 360 to 362
_, err := conn.GetEventAction(ctx, &dataexchange.GetEventActionInput{
EventActionId: aws.String(rs.Primary.ID),
})
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-resource Introduces a new resource. service/dataexchange Issues and PRs that pertain to the dataexchange service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[New Resource]: AWS Data Exchange - Job & AWS Data Exchange - Event Action
3 participants