generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Enterprise Organization operations (#398)
- Loading branch information
1 parent
858a644
commit 55b6c5d
Showing
7 changed files
with
204 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "astra_enterprise_org Resource - terraform-provider-astra" | ||
subcategory: "" | ||
description: |- | ||
enterprise_org resource represents an Organization that is created under an Enterprise in Astra. | ||
--- | ||
|
||
# astra_enterprise_org (Resource) | ||
|
||
`enterprise_org` resource represents an Organization that is created under an Enterprise in Astra. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# Create a new Enterprise organization | ||
resource "astra_enterprise_org" "entorg" { | ||
name = "My Enterprise Organization" | ||
email = "admin@example.com" | ||
admin_user_id = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d" | ||
enterprise_id = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `admin_user_id` (String) UUID of the Astra user that will be the admin of the organization | ||
- `email` (String) Organization email address | ||
- `name` (String) Organization name | ||
|
||
### Read-Only | ||
|
||
- `created_at` (String) The timestamp when the organization was created. | ||
- `enterprise_id` (String) UUID of the Enterprise under which the organization is created | ||
- `id` (String) The ID of this resource. | ||
- `last_modified` (String) The timestamp when the organization was last modified. | ||
- `organization_group_id` (String) The group ID (UUID) of the organization. | ||
- `organization_id` (String) The Astra organization ID (UUID) for the created Enterprise organization. | ||
- `organization_type` (String) The type of the organization. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# The import ID is the organization ID (UUID) | ||
terraform import astra_enterprise_org.example a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d | ||
``` |
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,2 @@ | ||
# The import ID is the organization ID (UUID) | ||
terraform import astra_enterprise_org.example a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d |
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,7 @@ | ||
# Create a new Enterprise organization | ||
resource "astra_enterprise_org" "entorg" { | ||
name = "My Enterprise Organization" | ||
email = "admin@example.com" | ||
admin_user_id = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d" | ||
enterprise_id = "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d" | ||
} |
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,140 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/datastax/astra-client-go/v2/astra" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceEnterpriseOrg() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "`enterprise_org` resource represents an Organization that is created under an Enterprise in Astra.", | ||
CreateContext: resourceEnterpriseOrgCreate, | ||
ReadContext: resourceEnterpriseOrgRead, | ||
DeleteContext: resourceEnterpriseOrgDelete, | ||
|
||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
// Required | ||
"name": { | ||
Description: "Organization name", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"email": { | ||
Description: "Organization email address", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"admin_user_id": { | ||
Description: "UUID of the Astra user that will be the admin of the organization", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
// Computed | ||
"enterprise_id": { | ||
Description: "UUID of the Enterprise under which the organization is created", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"organization_id": { | ||
Description: "The Astra organization ID (UUID) for the created Enterprise organization.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"organization_type": { | ||
Description: "The type of the organization.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"organization_group_id": { | ||
Description: "The group ID (UUID) of the organization.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_at": { | ||
Description: "The timestamp when the organization was created.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"last_modified": { | ||
Description: "The timestamp when the organization was last modified.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
// TODO: Add MarketPlaceData | ||
}, | ||
} | ||
} | ||
|
||
func resourceEnterpriseOrgCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(astraClients).astraClient.(*astra.ClientWithResponses) | ||
|
||
orgName := d.Get("name").(string) | ||
orgEmail := d.Get("email").(string) | ||
adminUid := d.Get("admin_user_id").(string) | ||
|
||
orgReq := astra.CreateOrganizationInEnterpriseJSONRequestBody{ | ||
Name: orgName, | ||
Email: orgEmail, | ||
AdminUserID: adminUid, | ||
} | ||
|
||
resp, err := client.CreateOrganizationInEnterpriseWithResponse(ctx, orgReq) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} else if resp.StatusCode() != 201 { | ||
return diag.Errorf("error adding Organization to Enterprise: Status: %s, %s", resp.Status(), resp.Body) | ||
} | ||
|
||
enterpriseOrg := resp.JSON201 | ||
|
||
d.SetId(*enterpriseOrg.OrganizationID) | ||
if err := setEnterpriseOrgData(d, enterpriseOrg); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
return nil | ||
} | ||
|
||
func resourceEnterpriseOrgRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
return diag.Diagnostics{ | ||
diag.Diagnostic{ | ||
Severity: diag.Warning, | ||
Summary: "Read of Enterprise Organizations not supported", | ||
Detail: "Read of Enterprise Organizations not supported.", | ||
}, | ||
} | ||
} | ||
|
||
func resourceEnterpriseOrgDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
return diag.Diagnostics{ | ||
diag.Diagnostic{ | ||
Severity: diag.Warning, | ||
Summary: "Delete of Enterprise Organizations not supported", | ||
Detail: "Delete of Enterprise Organizations not supported.", | ||
}, | ||
} | ||
} | ||
|
||
func setEnterpriseOrgData(d *schema.ResourceData, org *astra.CreateOrgInEnterpriseResponse) error { | ||
if org == nil { | ||
return errors.New("organization is nil") | ||
} | ||
d.Set("enterprise_id", *org.EnterpriseId) | ||
d.Set("organization_id", *org.OrganizationID) | ||
d.Set("organization_type", *org.OrgType) | ||
d.Set("organization_group_id", *org.OrganizationGroupId) | ||
d.Set("created_at", *org.CreatedAt) | ||
d.Set("last_modified", *org.LastModified) | ||
|
||
return nil | ||
} |