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.
* Adds astra_customer_key resource * Adds astra_customer_key datasource * Adds astra_customer_keys datasource * Adds astra_cloud_accounts datasource
- Loading branch information
1 parent
1b0f56a
commit 858a644
Showing
21 changed files
with
693 additions
and
7 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,49 @@ | ||
--- | ||
# 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 | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# AWS example | ||
data "astra_cloud_accounts" "awsaccounts" { | ||
cloud_provider = "aws" | ||
region = "us-east-1" | ||
} | ||
# GCP example | ||
data "astra_cloud_accounts" "gcpaccounts" { | ||
cloud_provider = "gcp" | ||
region = "us-east1" | ||
} | ||
``` | ||
|
||
<!-- 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,35 @@ | ||
--- | ||
# 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 | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# Read in a customer key for a given cloud provider and region | ||
data "astra_customer_key" "key" { | ||
cloud_provider = "aws" | ||
region = "us-east-1" | ||
} | ||
``` | ||
|
||
<!-- 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,37 @@ | ||
--- | ||
# 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 | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# Read in all customer keys for the given Organization | ||
data "astra_customer_keys" "keys" { | ||
} | ||
``` | ||
|
||
<!-- 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,52 @@ | ||
--- | ||
# 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). Note that DELETE is not supported through Terraform currently. A support ticket must be created to delete Customer Keys in Astra. WARNING: Deleting a key from Astra will result in an outage. Please see https://docs.datastax.com/en/astra-db-serverless/administration/delete-customer-keys.html for more information. | ||
--- | ||
|
||
# astra_customer_key (Resource) | ||
|
||
`astra_customer_key` provides a Customer Key resource for Astra's Bring Your Own Key (BYOK). Note that DELETE is not supported through Terraform currently. A support ticket must be created to delete Customer Keys in Astra. WARNING: Deleting a key from Astra will result in an outage. Please see https://docs.datastax.com/en/astra-db-serverless/administration/delete-customer-keys.html for more information. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# AWS example | ||
resource "astra_customer_key" "customerkey" { | ||
cloud_provider = "aws" | ||
region = "us-east-1" | ||
key_id = "arn:aws:kms:us-east-1:123456789012:key/1a2b3c4d-5e6f-1a2b-3c4d-5e6f1a2b3c4d" | ||
} | ||
# GCP example | ||
resource "astra_customer_key" "customerKey" { | ||
cloud_provider = "gcp" | ||
region = "us-east1" | ||
key_id = "projects/my-project/locations/us-east1/keyRings/my-key-ring/cryptoKeys/my-key" | ||
} | ||
``` | ||
|
||
<!-- 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. This is cloud provider specific. | ||
- `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). | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# the import id is in the fomrat of <orgId>/cloudProvider/<cloud_provider>/region/<region>/keyId/<key_id> | ||
terraform import astra_customer_key.customerkey 4d3c2b1a-5e6f-1a2b-3c4d-5e6f1a2b3c4d/cloudProvider/aws/region/us-east-1/keyId/arn:aws:kms:us-east-1:123456789012:key/1a2b3c4d-5e6f-1a2b-3c4d-5e6f1a2b3c4d | ||
``` |
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,11 @@ | ||
# AWS example | ||
data "astra_cloud_accounts" "awsaccounts" { | ||
cloud_provider = "aws" | ||
region = "us-east-1" | ||
} | ||
|
||
# GCP example | ||
data "astra_cloud_accounts" "gcpaccounts" { | ||
cloud_provider = "gcp" | ||
region = "us-east1" | ||
} |
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,5 @@ | ||
# Read in a customer key for a given cloud provider and region | ||
data "astra_customer_key" "key" { | ||
cloud_provider = "aws" | ||
region = "us-east-1" | ||
} |
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,3 @@ | ||
# Read in all customer keys for the given Organization | ||
data "astra_customer_keys" "keys" { | ||
} |
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 in the fomrat of <orgId>/cloudProvider/<cloud_provider>/region/<region>/keyId/<key_id> | ||
terraform import astra_customer_key.customerkey 4d3c2b1a-5e6f-1a2b-3c4d-5e6f1a2b3c4d/cloudProvider/aws/region/us-east-1/keyId/arn:aws:kms:us-east-1:123456789012:key/1a2b3c4d-5e6f-1a2b-3c4d-5e6f1a2b3c4d |
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,13 @@ | ||
# AWS example | ||
resource "astra_customer_key" "customerkey" { | ||
cloud_provider = "aws" | ||
region = "us-east-1" | ||
key_id = "arn:aws:kms:us-east-1:123456789012:key/1a2b3c4d-5e6f-1a2b-3c4d-5e6f1a2b3c4d" | ||
} | ||
|
||
# GCP example | ||
resource "astra_customer_key" "customerKey" { | ||
cloud_provider = "gcp" | ||
region = "us-east1" | ||
key_id = "projects/my-project/locations/us-east1/keyRings/my-key-ring/cryptoKeys/my-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
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,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 | ||
} |
Oops, something went wrong.