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: create resource to manage oauth2 clients #488

Merged
merged 7 commits into from
Nov 16, 2023

Conversation

mxm-tr
Copy link
Member

@mxm-tr mxm-tr commented Nov 6, 2023

Description

This PR adds support for the OAuth2 clients service accounts. API Docs

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Documentation update

How Has This Been Tested?

  • Unit tests: make test
  • Acceptance tests: TF_ACC=1 go test -run '^TestAccMeApiOauth2.*$' $(go list ./... |grep -v 'vendor') -v

Test Configuration:

  • Terraform version: terraform version: Terraform vx.y.z
  • Existing HCL configuration you used:
resource "ovh_me_api_oauth2_client" "my_oauth2_client_auth_code" {
  name = "my oauth2 client auth code"
  flow = "AUTHORIZATION_CODE"
  description = "A client for my app created from terraform"
  callback_urls = ["https://localhost:8080"]
}

resource "ovh_me_api_oauth2_client" "my_oauth2_client_client_creds" {
  name = "my oauth2 client client creds"
  flow = "CLIENT_CREDENTIALS"
  description = "A client for my app created from terraform"
}

data "ovh_me_api_oauth2_client" "my_data_oauth2_client" {
  client_id = "5f8969a993ec8b4a"
  client_secret = "secret"
}

output "test_get_client_name" {
    value = "${data.ovh_me_api_oauth2_client.my_data_oauth2_client.name}"
}

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or issues
  • I have added acceptance tests that prove my fix is effective or that my feature works
  • New and existing acceptance tests pass locally with my changes
  • I ran successfully go mod vendor if I added or modify go.mod file

@mxm-tr mxm-tr force-pushed the add-provider-for-oauth2-clients branch 2 times, most recently from e266267 to 0633cc7 Compare November 6, 2023 12:46
@mxm-tr mxm-tr force-pushed the add-provider-for-oauth2-clients branch from 0633cc7 to 1ecfef2 Compare November 6, 2023 12:51
@fehrnah fehrnah requested review from yomovh and rbeuque74 November 6, 2023 14:48
Description: "Client ID for the oauth2 client, generated during the resource creation.",
Required: true,
},
"client_secret": {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this field should be in the datasource as it can only be returned when creating an oAuth2 client

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking we could use this field to specify a data source with an existing client_secret. Do you think this use case is enough? If not I can remove it from the data source and document it better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the proper way for this would be to import a resource instead. You could declare a custom import function that would be used like this: terraform import ovh_me_api_oauth2_client "$id|$client_secret" or using a variable like this: terraform import -var "client_secret=$client_secret" ovh_me_api_oauth2_client.
(See doc here: https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-resource-import)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the quick answer, I just pushed an edit for the resources to be importable with a client_secret as you suggested, and removed the field from the data source:

terraform import  ovh_me_api_oauth2_client 'client_id|client_secret'

@amstuta amstuta merged commit 9fdd305 into ovh:master Nov 16, 2023
@mxm-tr mxm-tr deleted the add-provider-for-oauth2-clients branch November 16, 2023 14:29
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.

3 participants