Skip to content

databricks_service_principal_federation_policy #4635

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

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

Conversation

AntonBarkan
Copy link

@AntonBarkan AntonBarkan commented Apr 13, 2025

Changes

#4489

Tests

  • make test run locally
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • using Go SDK
  • using TF Plugin Framework

@AntonBarkan AntonBarkan requested review from a team as code owners April 13, 2025 19:34
@AntonBarkan AntonBarkan requested review from rauchy and removed request for a team April 13, 2025 19:34
@AntonBarkan
Copy link
Author

@rauchy Would you be able to review this?

return err
}
name := spfp.Name
d.SetId(name[strings.LastIndex(name, "/")+1:])
Copy link

Choose a reason for hiding this comment

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

I'm not sure I understand this. If name is optional and can be user-specified then I don't think we can assume it is the ID ("uid" field). Though, Databricks docs say "if specified in a request, must match the value in the request URL", but they must be referring to account ID and SP ID because policy ID is not in the URL and is not known until the policy is created.

https://docs.databricks.com/api/account/serviceprincipalfederationpolicy/create

It seems simpler to just use the uid field, directly, since this is what the API expects for update/delete requests, not necessarily the last part of the name.

https://pkg.go.dev/github.com/databricks/[email protected]/service/oauth2#FederationPolicy

Suggested change
d.SetId(name[strings.LastIndex(name, "/")+1:])
d.SetId(spfp.Uid)

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for taking the time to review my pull request. This part was very confusing to me as well, and I’d like to explain what I’ve understood.

So, if the name is not set, then the generated name looks like:
accounts/482323ec-21a2-4d23-a4bb-4fdacf0ee506/servicePrincipals/2479342822644814/federationPolicies/388f001e-5f0a-42c3-bc0d-5da1a33a3798,
where the last part equals the value of the uid field. and available at the link https://accounts.cloud.databricks.com/api/2.0/accounts/482323ec-21a2-4d23-a4bb-4fdacf0ee506/servicePrincipals/2479342822644814/federationPolicies/388f001e-5f0a-42c3-bc0d-5da1a33a3798

Now let’s consider a example where the user sets the name manually. Any name that does not start with
accounts/482323ec-21a2-4d23-a4bb-4fdacf0ee506/servicePrincipals/2479342822644814/federationPolicies/
will be rejected.

The last part of the name may only contain letters, numbers, and hyphens.

For example, if I create a policy with the name:
accounts/482323ec-21a2-4d23-a4bb-4fdacf0ee506/servicePrincipals/2479342822644814/federationPolicies/fdfsd,
then it will be accessible via:
https://accounts.cloud.databricks.com/api/2.0/accounts/482323ec-21a2-4d23-a4bb-4fdacf0ee506/servicePrincipals/2479342822644814/federationPolicies/fdfsd

Whereas the link:
https://accounts.cloud.databricks.com/api/2.0/accounts/482323ec-21a2-4d23-a4bb-4fdacf0ee506/servicePrincipals/2479342822644814/federationPolicies/4e09f9a3-bb95-4e3d-a47c-9c437803d7cd
will return 404.

Copy link

Choose a reason for hiding this comment

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

Oh, you are right, I just double checked with the CLI. Thanks for explaining! It's quite strange because Databricks calls this part "policy id" in their API docs, but the examples suggest it is the end part of the name, like you say.

https://docs.databricks.com/api/account/serviceprincipalfederationpolicy/get

Copy link
Author

Choose a reason for hiding this comment

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

I’ve updated the code so that the UUID is used as the ID and is unique. I’d really appreciate it if you could review it

@AntonBarkan AntonBarkan requested a review from GFernie April 25, 2025 20:48
Copy link

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/terraform

Inputs:

  • PR number: 4635
  • Commit SHA: 9483125d276b60490d9713facaacbb9820005718

Checks will be approved automatically on success.

)

func ResourceServicePrincipalFederationPolicy() common.Resource {
s := map[string]*schema.Schema{
Copy link

Choose a reason for hiding this comment

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

As I understand it, the contribution guide asks that the schema is created using common.StructToSchema.

https://github.com/databricks/terraform-provider-databricks/blob/main/CONTRIBUTING.md#adding-a-new-resource

For example:

spnSecretSchema := common.StructToSchema(ServicePrincipalSecret{},

This looks like the correct struct to use:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants