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

SSO: Improve Azure AD validation #1390

Merged
merged 9 commits into from
Apr 11, 2024

Conversation

mgyongyosi
Copy link
Contributor

@mgyongyosi mgyongyosi commented Feb 29, 2024

This modifies the validation rules for azuread by ensuring the field api_url is empty. There are no changes for the other providers.

Copy link

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

@mgyongyosi mgyongyosi changed the title SSO: Improve Azure AD validation [WIP] SSO: Improve Azure AD validation Feb 29, 2024
@dmihai dmihai changed the title [WIP] SSO: Improve Azure AD validation SSO: Improve Azure AD validation Apr 9, 2024
@dmihai dmihai marked this pull request as ready for review April 9, 2024 07:13
@dmihai dmihai requested a review from a team as a code owner April 9, 2024 07:13
@dmihai dmihai requested a review from a team April 9, 2024 07:13
@julienduchesne
Copy link
Member

I think all of these validations should go in a CustomizeDiff function. example:

CreateContext: UpdateSSOSettings,
		ReadContext:   ReadSSOSettings,
		UpdateContext: UpdateSSOSettings,
		DeleteContext: DeleteSSOSettings,
		Importer: &schema.ResourceImporter{
			StateContext: schema.ImportStatePassthroughContext,
		},

		CustomizeDiff: func(ctx context.Context, rd *schema.ResourceDiff, i interface{}) error {
			providerName := rd.Get(providerKey).(string)
			// validation + relevant error message for each failure
		},

Then, you should have more than one test for various failing validations

@dmihai
Copy link
Contributor

dmihai commented Apr 10, 2024

@julienduchesne I did a research on how we can use CustomizeDiff to validate the input. The first thing I found was that the CustomizeDiff function is executed after a plan has been generated. This means we cannot fail early in case the input from the terraform config is invalid. I tried to find some other ways to perform conditional validations in terraform plugin sdk v2 but apparently there are none.

For that reason I think we should keep the way we do validations now. Please let me know if I'm missing something, I might have misunderstood your suggestion.

@julienduchesne
Copy link
Member

julienduchesne commented Apr 10, 2024

👍 That works. I think the ideal validation scenario would've been to not have a provider_name attribute and instead have a different block for each kind of auth (github { ... } OR gitlab { ... } ...). Then, we could've had ValidateFunc for attributes in each one (terraform validate would then work). Up to you if you want to refactor that way or not, major version is coming soon and the SSO resource is new, so it's the right time to change that.

If not, my one comment then is that I'd like all of these validations to have SSO in their name because they are specific to the SSO resource or be grouped in a helper struct (SSOResourceValidations.bla or something like that)

@dmihai
Copy link
Contributor

dmihai commented Apr 10, 2024

👍 That works. I think the ideal validation scenario would've been to not have a provider_name attribute and instead have a different block for each kind of auth (github { ... } OR gitlab { ... } ...). Then, we could've had ValidateFunc for attributes in each one (terraform validate would then work). Up to you if you want to refactor that way or not, major version is coming soon and the SSO resource is new, so it's the right time to change that.

If not, my one comment then is that I'd like all of these validations to have SSO in their name because they are specific to the SSO resource or be grouped in a helper struct (SSOResourceValidations.bla or something like that)

I don't think it's a good idea to change the structure of the sso resource now because some users are already using it. I'll try to group the validators to make the code more clear.

Copy link
Member

@julienduchesne julienduchesne left a comment

Choose a reason for hiding this comment

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

:shipit:

@dmihai dmihai merged commit 1b3c082 into main Apr 11, 2024
27 checks passed
@dmihai dmihai deleted the mgyongyosi/improve-azuread-settings-sso-resource branch April 11, 2024 14:48
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.

None yet

3 participants