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.
- Loading branch information
1 parent
1b0f56a
commit b986502
Showing
13 changed files
with
558 additions
and
4 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,35 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "astra_cloud_accounts Data Source - terraform-provider-astra" | ||
subcategory: "" | ||
description: |- | ||
Retrieve a list of Cloud Accounts within an Organization | ||
--- | ||
|
||
# astra_cloud_accounts (Data Source) | ||
|
||
Retrieve a list of Cloud Accounts within an Organization | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cloud_provider` (String) The cloud provider where the Customer Key exists (Currently supported: aws, gcp) | ||
- `region` (String) Cloud provider region | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `results` (List of Object) The list of Cloud Accounts for the given Organization. (see [below for nested schema](#nestedatt--results)) | ||
|
||
<a id="nestedatt--results"></a> | ||
### Nested Schema for `results` | ||
|
||
Read-Only: | ||
|
||
- `organization_id` (String) | ||
- `provider` (String) | ||
- `provider_id` (String) |
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,27 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "astra_customer_key Data Source - terraform-provider-astra" | ||
subcategory: "" | ||
description: |- | ||
Retrieve a Customer Key for a given cloud provider and region | ||
--- | ||
|
||
# astra_customer_key (Data Source) | ||
|
||
Retrieve a Customer Key for a given cloud provider and region | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cloud_provider` (String) The cloud provider where the Customer Key exists (Currently supported: aws, gcp) | ||
- `region` (String) Cloud provider region | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `key_id` (String) The Customer Key ID | ||
- `organization_id` (String) Organization ID |
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,31 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "astra_customer_keys Data Source - terraform-provider-astra" | ||
subcategory: "" | ||
description: |- | ||
Retrieve a list of Customer Keys within an Organization | ||
--- | ||
|
||
# astra_customer_keys (Data Source) | ||
|
||
Retrieve a list of Customer Keys within an Organization | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `results` (List of Object) The list of Customer Keys for the given Organization. (see [below for nested schema](#nestedatt--results)) | ||
|
||
<a id="nestedatt--results"></a> | ||
### Nested Schema for `results` | ||
|
||
Read-Only: | ||
|
||
- `cloud_provider` (String) | ||
- `key_id` (String) | ||
- `organization_id` (String) | ||
- `region` (String) |
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,27 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "astra_customer_key Resource - terraform-provider-astra" | ||
subcategory: "" | ||
description: |- | ||
astra_customer_key provides a Customer Key resource for Astra's Bring Your Own Key (BYOK). | ||
--- | ||
|
||
# astra_customer_key (Resource) | ||
|
||
`astra_customer_key` provides a Customer Key resource for Astra's Bring Your Own Key (BYOK). | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cloud_provider` (String) The cloud provider where the Customer Key exists (Currently supported: aws, gcp) | ||
- `key_id` (String) Customer Key ID. | ||
- `region` (String) Region in which the Customer Key exists. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `organization_id` (String) The Astra organization ID (this is derived from the token used to create the Customer Key). |
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,101 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/datastax/astra-client-go/v2/astra" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
func dataSourceCloudAccounts() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Retrieve a list of Cloud Accounts within an Organization", | ||
|
||
ReadContext: dataSourceCloudAccountsRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
// Required inputs | ||
"cloud_provider": { | ||
Description: "The cloud provider where the Customer Key exists (Currently supported: aws, gcp)", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice(availableBYOKCloudProviders, true), | ||
DiffSuppressFunc: ignoreCase, | ||
}, | ||
"region": { | ||
Description: "Cloud provider region", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
// Computed outputs | ||
"results": { | ||
Type: schema.TypeList, | ||
Description: "The list of Cloud Accounts for the given Organization.", | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"organization_id": { | ||
Description: "Organization ID", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"provider": { | ||
Description: "The cloud provider", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"provider_id": { | ||
Description: "The provider account ID", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCloudAccountsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(astraClients).astraClient.(*astra.ClientWithResponses) | ||
provider := d.Get("cloud_provider").(string) | ||
region := d.Get("region").(string) | ||
|
||
cloudAccounts, err := listCloudAccounts(ctx, client, provider, region) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := d.Set("results", cloudAccounts); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(id.UniqueId()) | ||
return nil | ||
} | ||
|
||
func listCloudAccounts(ctx context.Context, client *astra.ClientWithResponses, cloudProvider, region string) ([]map[string]interface{}, error) { | ||
resp, err := client.GetCloudAccountsWithResponse(ctx, cloudProvider, region) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if resp.StatusCode() != http.StatusOK { | ||
return nil, fmt.Errorf("Error fetching Customer Keys. Status: %d, Message: %s", resp.StatusCode(), (resp.Body)) | ||
} | ||
cloudAccounts := resp.JSON200 | ||
result := make([]map[string]interface{}, 0, len(*cloudAccounts)) | ||
for _, account := range *cloudAccounts { | ||
result = append(result, map[string]interface{}{ | ||
"organization_id" : account.OrganizationId, | ||
"provider" : account.Provider, | ||
"provider_id" : account.ProviderId, | ||
}) | ||
} | ||
return result, 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,72 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"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" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
func dataSourceCustomerKey() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Retrieve a Customer Key for a given cloud provider and region", | ||
|
||
ReadContext: dataSourceCustomerKeyRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
// Required inputs | ||
"cloud_provider": { | ||
Description: "The cloud provider where the Customer Key exists (Currently supported: aws, gcp)", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice(availableBYOKCloudProviders, true), | ||
DiffSuppressFunc: ignoreCase, | ||
}, | ||
"region": { | ||
Description: "Cloud provider region", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
// Computed outputs | ||
"organization_id": { | ||
Description: "Organization ID", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"key_id": { | ||
Description: "The Customer Key ID", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCustomerKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(astraClients).astraClient.(*astra.ClientWithResponses) | ||
cloudProvider := d.Get("cloud_provider").(string) | ||
region := d.Get("region").(string) | ||
|
||
customerKeys, err := listCustomerKeys(ctx, client) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
for _, key := range customerKeys { | ||
if strings.EqualFold(cloudProvider, key["cloud_provider"].(string)) && | ||
region == key["region].(string)"] { | ||
orgId := key["organization_id"].(string) | ||
keyId := key["key_id"].(string) | ||
d.Set("organization_id", orgId) | ||
d.Set("key_id", keyId) | ||
d.SetId(fmt.Sprintf("%s/%s/%s", orgId, cloudProvider, region)) | ||
return nil | ||
} | ||
} | ||
// key not found | ||
return diag.Errorf("No Customer Key found for provider: %s, region: %s", cloudProvider, region) | ||
} |
Oops, something went wrong.