generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add BYOK resource #330
Merged
Merged
Add BYOK resource #330
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b986502
Add BYOK resource
emerkle826 90f3425
[fixup] Update docs and return warning on delete of Customer Key
emerkle826 ed5ef94
Fix missing OrgId in create customer key request
emerkle826 8d43517
Chnage expected response from 200 to 201
emerkle826 5e17d91
Handle non-200 response fetching orgId
emerkle826 b09abbc
Fix customer_key data source and add docs
emerkle826 5f57fa3
Add cloud_accounts docs
emerkle826 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably more a of a question for the DevOps API folks, but will this only ever return an array of length 1, or are there situations where Astra organizations will have more than one cloud accounts for a given cloud provider and region?
I ask since the primary use case for this data source is to be able to feed it into an AWS KMS access policy, which would require creating an ARN based on the
provider_id
returned in this data source's response. I'm curious if it is safe to just refer to it withdata.astra_cloud_accounts.this[0].provider_id
, or if some HCL manipulation needs to be done to turn it into an array of provider IDs/ARNs for the KMS key policy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For GCP, I happen to have 2 accounts, so it can be more than 1. That may only be the case for GCP, but the code handles both AWS and GCP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can happen to aws too.