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

feat(spn): created service principal name data source #38307

Merged

Conversation

myerscf
Copy link
Contributor

@myerscf myerscf commented Jul 9, 2024

Description

This PR is for a data source: aws_service_principal. It will be used for generating a Service Principal Name (SPN) for a service (with region), which can be then be used in places that need to reference it - mainly for when writing IAM Policies.

Service Principals Names should always end in the standard global format: {servicename}.amazonaws.com - however there are edge cases where this is not the case.

Some Service Principals Names could look different (e.g. in ISO regions) were SPNs where different, as they where made before AWS standardised its policies.

Using this data source, users can create a reference to use - which will do the heavy lifting of looking for regional difference fallbacks.

Relations

N/A

References

CDK equivalent

Output from Acceptance Testing

% make testacc TESTS=TestAccServicePrincipalName PKG=meta

=== RUN   TestAccServicePrincipalName
=== PAUSE TestAccServicePrincipalName
=== RUN   TestAccServicePrincipalName_MissingService
=== PAUSE TestAccServicePrincipalName_MissingService
=== RUN   TestAccServicePrincipalNameByRegion
=== RUN   TestAccServicePrincipalNameByRegion/us-east-1
=== RUN   TestAccServicePrincipalNameByRegion/cn-north-1
=== RUN   TestAccServicePrincipalNameByRegion/us-gov-east-1
=== RUN   TestAccServicePrincipalNameByRegion/us-iso-east-1
=== RUN   TestAccServicePrincipalNameByRegion/us-isob-east-1
=== RUN   TestAccServicePrincipalNameByRegion/eu-isoe-west-1
--- PASS: TestAccServicePrincipalNameByRegion (50.61s)
    --- PASS: TestAccServicePrincipalNameByRegion/us-east-1 (9.23s)
    --- PASS: TestAccServicePrincipalNameByRegion/cn-north-1 (8.06s)
    --- PASS: TestAccServicePrincipalNameByRegion/us-gov-east-1 (8.73s)
    --- PASS: TestAccServicePrincipalNameByRegion/us-iso-east-1 (8.09s)
    --- PASS: TestAccServicePrincipalNameByRegion/us-isob-east-1 (8.02s)
    --- PASS: TestAccServicePrincipalNameByRegion/eu-isoe-west-1 (8.49s)
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/cloudhsm
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/config
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/logs
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/states
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/workspaces
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/us-isob-east-1/dms
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/us-isob-east-1/logs
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/cn-north-1/codedeploy
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/cn-north-1/elasticmapreduce
=== RUN   TestAccServicePrincipalName_UniqueForServiceInRegion/cn-north-1/logs
--- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion (82.77s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/cloudhsm (8.21s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/config (8.12s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/logs (8.13s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/states (8.28s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/us-iso-east-1/workspaces (8.47s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/us-isob-east-1/dms (8.64s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/us-isob-east-1/logs (8.27s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/cn-north-1/codedeploy (8.29s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/cn-north-1/elasticmapreduce (8.19s)
    --- PASS: TestAccServicePrincipalName_UniqueForServiceInRegion/cn-north-1/logs (8.18s)
=== CONT  TestAccServicePrincipalName
=== CONT  TestAccServicePrincipalName_MissingService
--- PASS: TestAccServicePrincipalName_MissingService (0.85s)
--- PASS: TestAccServicePrincipalName (8.63s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/meta       149.506s
...

Signed-off-by: Fred Myerscough <myerscf@amazon.co.uk>
@myerscf myerscf requested a review from a team as a code owner July 9, 2024 22:04
Copy link

github-actions bot commented Jul 9, 2024

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 documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. generators Relates to code generators. service/meta Issues and PRs that pertain to the meta service. size/XL Managed by automation to categorize the size of a PR. and removed documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. generators Relates to code generators. service/meta Issues and PRs that pertain to the meta service. labels Jul 9, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Jul 9, 2024
Signed-off-by: Fred Myerscough <myerscf@amazon.co.uk>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome @myerscf 👋

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 CONTRIBUTOR 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! 😃

@github-actions github-actions bot added documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. generators Relates to code generators. service/meta Issues and PRs that pertain to the meta service. labels Jul 9, 2024
@justinretzolk justinretzolk added new-data-source Introduces a new data source. and removed needs-triage Waiting for first response or review from a maintainer. labels Jul 10, 2024
@YakDriver YakDriver self-assigned this Jul 24, 2024
@YakDriver
Copy link
Member

I'm getting a failure in the acceptance tests. Otherwise, this LGTM

    service_principal_data_source_test.go:137: Step 1/1 error: Check failed: Check 1/4 error: data.aws_service_principal.test: Attribute 'id' expected "states.us-iso-east-1.c2s.ic.gov", got "states.us-iso-east-1.amazonaws.com"
--- FAIL: TestAccMetaServicePrincipal_UniqueForServiceInRegion (0.00s)
    --- FAIL: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/states (9.81s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/dms (18.07s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/logs (18.07s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/config (18.08s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/cloudhsm (18.08s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/workspaces (18.10s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/elasticmapreduce (18.10s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/codedeploy (18.10s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/logs (18.10s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/logs (18.10s)

Signed-off-by: Fred Myerscough <myerscf@amazon.co.uk>
@myerscf
Copy link
Contributor Author

myerscf commented Jul 24, 2024

I'm getting a failure in the acceptance tests. Otherwise, this LGTM

    service_principal_data_source_test.go:137: Step 1/1 error: Check failed: Check 1/4 error: data.aws_service_principal.test: Attribute 'id' expected "states.us-iso-east-1.c2s.ic.gov", got "states.us-iso-east-1.amazonaws.com"
--- FAIL: TestAccMetaServicePrincipal_UniqueForServiceInRegion (0.00s)
    --- FAIL: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/states (9.81s)

Fixed - states was removed from aws-iso fallback naming, forgot to update the test!

Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! LGTM 🎉

% make t T=TestAccMetaServicePrincipal_ K=meta
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.5 test ./internal/service/meta/... -v -count 1 -parallel 20 -run='TestAccMetaServicePrincipal_'  -timeout 360m
=== RUN   TestAccMetaServicePrincipal_basic
=== PAUSE TestAccMetaServicePrincipal_basic
=== RUN   TestAccMetaServicePrincipal_MissingService
=== PAUSE TestAccMetaServicePrincipal_MissingService
=== RUN   TestAccMetaServicePrincipal_ByRegion
=== RUN   TestAccMetaServicePrincipal_ByRegion/us-east-1
=== PAUSE TestAccMetaServicePrincipal_ByRegion/us-east-1
=== RUN   TestAccMetaServicePrincipal_ByRegion/cn-north-1
=== PAUSE TestAccMetaServicePrincipal_ByRegion/cn-north-1
=== RUN   TestAccMetaServicePrincipal_ByRegion/us-gov-east-1
=== PAUSE TestAccMetaServicePrincipal_ByRegion/us-gov-east-1
=== RUN   TestAccMetaServicePrincipal_ByRegion/us-iso-east-1
=== PAUSE TestAccMetaServicePrincipal_ByRegion/us-iso-east-1
=== RUN   TestAccMetaServicePrincipal_ByRegion/us-isob-east-1
=== PAUSE TestAccMetaServicePrincipal_ByRegion/us-isob-east-1
=== RUN   TestAccMetaServicePrincipal_ByRegion/eu-isoe-west-1
=== PAUSE TestAccMetaServicePrincipal_ByRegion/eu-isoe-west-1
=== CONT  TestAccMetaServicePrincipal_ByRegion/us-east-1
=== CONT  TestAccMetaServicePrincipal_ByRegion/eu-isoe-west-1
=== CONT  TestAccMetaServicePrincipal_ByRegion/us-iso-east-1
=== CONT  TestAccMetaServicePrincipal_ByRegion/us-gov-east-1
=== CONT  TestAccMetaServicePrincipal_ByRegion/cn-north-1
=== CONT  TestAccMetaServicePrincipal_ByRegion/us-isob-east-1
--- PASS: TestAccMetaServicePrincipal_ByRegion (0.00s)
    --- PASS: TestAccMetaServicePrincipal_ByRegion/us-iso-east-1 (14.75s)
    --- PASS: TestAccMetaServicePrincipal_ByRegion/us-east-1 (14.80s)
    --- PASS: TestAccMetaServicePrincipal_ByRegion/eu-isoe-west-1 (14.80s)
    --- PASS: TestAccMetaServicePrincipal_ByRegion/us-isob-east-1 (14.80s)
    --- PASS: TestAccMetaServicePrincipal_ByRegion/us-gov-east-1 (14.81s)
    --- PASS: TestAccMetaServicePrincipal_ByRegion/cn-north-1 (14.81s)
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/cloudhsm
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/cloudhsm
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/config
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/config
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/logs
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/logs
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/workspaces
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/workspaces
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/dms
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/dms
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/logs
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/logs
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/codedeploy
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/codedeploy
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/elasticmapreduce
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/elasticmapreduce
=== RUN   TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/logs
=== PAUSE TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/logs
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/cloudhsm
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/codedeploy
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/logs
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/elasticmapreduce
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/workspaces
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/logs
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/dms
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/logs
=== CONT  TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/config
--- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion (0.00s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/elasticmapreduce (18.18s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/codedeploy (18.19s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/config (18.19s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/dms (18.19s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/logs (18.19s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/cloudhsm (18.21s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-iso-east-1/workspaces (18.21s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/us-isob-east-1/logs (18.21s)
    --- PASS: TestAccMetaServicePrincipal_UniqueForServiceInRegion/cn-north-1/logs (18.21s)
=== CONT  TestAccMetaServicePrincipal_basic
=== CONT  TestAccMetaServicePrincipal_MissingService
--- PASS: TestAccMetaServicePrincipal_MissingService (1.33s)
--- PASS: TestAccMetaServicePrincipal_basic (9.47s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/meta	45.352s

@YakDriver YakDriver merged commit f90bb3b into hashicorp:main Jul 24, 2024
43 checks passed
@github-actions github-actions bot added this to the v5.60.0 milestone Jul 24, 2024
Copy link

This functionality has been released in v5.60.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!

@myerscf myerscf deleted the feature/aws_service_principal_name_data_source branch August 5, 2024 12:44
Copy link

github-actions bot commented Sep 6, 2024

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2024
@justinretzolk justinretzolk added the partner Contribution from a partner. label Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. generators Relates to code generators. new-data-source Introduces a new data source. partner Contribution from a partner. service/meta Issues and PRs that pertain to the meta service. size/XL Managed by automation to categorize the size of a PR. 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.

4 participants