-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new resource to manage Organization Client Grants (#1027)
* Added new resource and data source for org client grants * minor refactoring * Added test case * Updated test recordings * Updated the test name * Fix some timing issues in resourceserver, and add terraform version to server logs * Remove unneeded lint config * rebased * minor refactoring * Added test case * Updated test recordings * Updated the test name * Fix some timing issues in resourceserver, and add terraform version to server logs * Remove unneeded lint config --------- Co-authored-by: A. Craig West <[email protected]>
- Loading branch information
1 parent
1a3b628
commit 46fe82e
Showing
22 changed files
with
14,674 additions
and
8,219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
page_title: "Resource: auth0_organization_client_grant" | ||
description: |- | ||
With this resource, you can manage a client grant associated with an organization. | ||
--- | ||
|
||
# Resource: auth0_organization_client_grant | ||
|
||
With this resource, you can manage a client grant associated with an organization. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `grant_id` (String) A Client Grant ID to add to the organization. | ||
- `organization_id` (String) The ID of the organization to associate the client grant. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package organization | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/auth0/terraform-provider-auth0/internal/config" | ||
internalError "github.com/auth0/terraform-provider-auth0/internal/error" | ||
internalSchema "github.com/auth0/terraform-provider-auth0/internal/schema" | ||
) | ||
|
||
// NewOrganizationClientGrantResource will return a new auth0_organization_client_grant resource. | ||
func NewOrganizationClientGrantResource() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "With this resource, you can manage a client grant associated with an organization.", | ||
CreateContext: createOrganizationClientGrant, | ||
ReadContext: readOrganizationClientGrant, | ||
DeleteContext: deleteOrganizationClientGrant, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: internalSchema.ImportResourceGroupID("organization_id", "grant_id"), | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"organization_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "The ID of the organization to associate the client grant.", | ||
}, | ||
"grant_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "A Client Grant ID to add to the organization.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func createOrganizationClientGrant(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
api := meta.(*config.Config).GetAPI() | ||
organizationID := data.Get("organization_id").(string) | ||
grantID := data.Get("grant_id").(string) | ||
|
||
if err := api.Organization.AssociateClientGrant(ctx, organizationID, grantID); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
internalSchema.SetResourceGroupID(data, organizationID, grantID) | ||
|
||
return readOrganizationClientGrant(ctx, data, meta) | ||
} | ||
|
||
func readOrganizationClientGrant(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
api := meta.(*config.Config).GetAPI() | ||
|
||
organizationID := data.Get("organization_id").(string) | ||
clientGrantList, err := api.Organization.ClientGrants(ctx, organizationID) | ||
|
||
if err != nil { | ||
return diag.FromErr(internalError.HandleAPIError(data, err)) | ||
} | ||
|
||
grantID := data.Get("grant_id").(string) | ||
for _, grant := range clientGrantList.ClientGrants { | ||
if grant.GetID() == grantID { | ||
return nil | ||
} | ||
} | ||
|
||
data.SetId("") | ||
return nil | ||
} | ||
|
||
func deleteOrganizationClientGrant(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
api := meta.(*config.Config).GetAPI() | ||
|
||
organizationID := data.Get("organization_id").(string) | ||
grantID := data.Get("grant_id").(string) | ||
|
||
if err := api.Organization.RemoveClientGrant(ctx, organizationID, grantID); err != nil { | ||
return diag.FromErr(internalError.HandleAPIError(data, err)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package organization_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
|
||
"github.com/auth0/terraform-provider-auth0/internal/acctest" | ||
) | ||
|
||
const testAssociateOrganizationClientGrant = ` | ||
resource "auth0_organization" "my_organization" { | ||
name = "test-org-acceptance-testing" | ||
display_name = "Test Org Acceptance Testing" | ||
} | ||
resource "auth0_resource_server" "new_resource_server" { | ||
depends_on = [ auth0_organization.my_organization ] | ||
name = "Example API" | ||
identifier = "https://api.travel00123.com/" | ||
} | ||
resource "auth0_client" "my_test_client"{ | ||
depends_on = [ auth0_organization.my_organization, auth0_resource_server.new_resource_server ] | ||
name = "test_client" | ||
organization_usage = "allow" | ||
default_organization { | ||
organization_id = auth0_organization.my_organization.id | ||
flows = ["client_credentials"] | ||
} | ||
} | ||
resource "auth0_client_grant" "my_client_grant" { | ||
depends_on = [ auth0_resource_server.new_resource_server, auth0_client.my_test_client ] | ||
client_id = auth0_client.my_test_client.id | ||
audience = auth0_resource_server.new_resource_server.identifier | ||
scopes = ["create:organization_client_grants","create:resource"] | ||
allow_any_organization = true | ||
organization_usage = "allow" | ||
} | ||
resource "auth0_organization_client_grant" "associate_org_client_grant"{ | ||
depends_on = [ auth0_client_grant.my_client_grant ] | ||
organization_id = auth0_organization.my_organization.id | ||
grant_id = auth0_client_grant.my_client_grant.id | ||
} | ||
data "auth0_organization" "retrieve_org_data" { | ||
depends_on = [ auth0_organization_client_grant.associate_org_client_grant ] | ||
organization_id = auth0_organization.my_organization.id | ||
} | ||
` | ||
|
||
func TestAccOrganizationClientGrant(t *testing.T) { | ||
acctest.Test(t, resource.TestCase{ | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: acctest.ParseTestName(testAssociateOrganizationClientGrant, t.Name()), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("auth0_organization_client_grant.associate_org_client_grant", "organization_id"), | ||
resource.TestCheckResourceAttrSet("auth0_organization_client_grant.associate_org_client_grant", "grant_id"), | ||
resource.TestCheckResourceAttrSet("data.auth0_organization.retrieve_org_data", "client_grants.0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.