Skip to content

Commit

Permalink
Rename auth0_encryption_key to auth0_encryption_key_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
acwest committed Sep 27, 2024
1 parent 4039d95 commit 3c2d16f
Show file tree
Hide file tree
Showing 10 changed files with 515 additions and 515 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
page_title: "Resource: auth0_encryption_key"
page_title: "Resource: auth0_encryption_key_manager"
description: |-
Resource to allow the rekeying of your tenant master key.
---

# Resource: auth0_encryption_key
# Resource: auth0_encryption_key_manager

Resource to allow the rekeying of your tenant master key.

## Example Usage

```terraform
resource "auth0_encryption_key" "my_encryption_key_initial" {
resource "auth0_encryption_key_manager" "my_encryption_key_manager_initial" {
key_rotation_id = "da9f2f3b-1c7e-4245-8982-9a25da8407c4"
}
resource "auth0_encryption_key" "my_encryption_key_rekey" {
resource "auth0_encryption_key_manager" "my_encryption_key_manager_rekey" {
key_rotation_id = "68feba2c-7768-40f3-9d71-4b91e0233abf"
}
```
Expand All @@ -25,7 +25,7 @@ resource "auth0_encryption_key" "my_encryption_key_rekey" {

### Optional

- `key_rotation_id` (String) If set to to a new value, the encryption keys will be rotated.
- `key_rotation_id` (String) If this value is changed, the encryption keys will be rotated. A UUID is recommended for the `key_rotation_id`.

### Read-Only

Expand All @@ -50,10 +50,10 @@ Import is supported using the following syntax:

```shell
# As this is not a resource identifiable by an ID within the Auth0 Management API,
# auth0_encryption_key can be imported using a random string.
# auth0_encryption_key_manager can be imported using a random string.
#
# We recommend [Version 4 UUID](https://www.uuidgenerator.net/version4)
#
# Example:
terraform import auth0_encryption_key.my_key "6f0519ad-ea35-44a3-9b0e-ac9c631612c2"
terraform import auth0_encryption_key_manager.my_key_manager "6f0519ad-ea35-44a3-9b0e-ac9c631612c2"
```
8 changes: 0 additions & 8 deletions examples/resources/auth0_encryption_key/resource.tf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# As this is not a resource identifiable by an ID within the Auth0 Management API,
# auth0_encryption_key can be imported using a random string.
# auth0_encryption_key_manager can be imported using a random string.
#
# We recommend [Version 4 UUID](https://www.uuidgenerator.net/version4)
#
# Example:
terraform import auth0_encryption_key.my_key "6f0519ad-ea35-44a3-9b0e-ac9c631612c2"
terraform import auth0_encryption_key_manager.my_key_manager "6f0519ad-ea35-44a3-9b0e-ac9c631612c2"
8 changes: 8 additions & 0 deletions examples/resources/auth0_encryption_key_manager/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "auth0_encryption_key_manager" "my_encryption_key_manager_initial" {
key_rotation_id = "da9f2f3b-1c7e-4245-8982-9a25da8407c4"
}

resource "auth0_encryption_key_manager" "my_encryption_key_manager_rekey" {
key_rotation_id = "68feba2c-7768-40f3-9d71-4b91e0233abf"
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package encryptionkey
package encryptionkeymanager

import (
"github.com/auth0/go-auth0/management"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package encryptionkey
package encryptionkeymanager

import (
"context"
Expand All @@ -10,19 +10,19 @@ import (
"github.com/auth0/terraform-provider-auth0/internal/config"
)

// NewEncryptionKeyResource will return a new auth0_encryption_keys resource.
func NewEncryptionKeyResource() *schema.Resource {
// NewEncryptionKeyManagerResource will return a new auth0_encryption_key_manager resource.
func NewEncryptionKeyManagerResource() *schema.Resource {
return &schema.Resource{
CreateContext: createEncryptionKey,
UpdateContext: updateEncryptionKey,
ReadContext: readEncryptionKey,
DeleteContext: deleteEncryptionKey,
CreateContext: createEncryptionKeyManager,
UpdateContext: updateEncryptionKeyManager,
ReadContext: readEncryptionKeyManager,
DeleteContext: deleteEncryptionKeyManager,
Description: "Resource to allow the rekeying of your tenant master key.",
Schema: map[string]*schema.Schema{
"key_rotation_id": {
Type: schema.TypeString,
Optional: true,
Description: "If set to to a new value, the encryption keys will be rotated.",
Description: "If this value is changed, the encryption keys will be rotated. A UUID is recommended for the `key_rotation_id`.",
},
"encryption_keys": {
Type: schema.TypeList,
Expand Down Expand Up @@ -70,16 +70,16 @@ func NewEncryptionKeyResource() *schema.Resource {
}
}

func createEncryptionKey(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
func createEncryptionKeyManager(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
data.SetId(id.UniqueId())

return updateEncryptionKey(ctx, data, meta)
return updateEncryptionKeyManager(ctx, data, meta)
}

func updateEncryptionKey(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
func updateEncryptionKeyManager(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

if data.IsNewResource() || data.HasChange("key_rotation_id") {
if !data.IsNewResource() && data.HasChange("key_rotation_id") {
keyRotationID := data.GetRawConfig().GetAttr("key_rotation_id")
if !keyRotationID.IsNull() && len(keyRotationID.AsString()) > 0 {
if err := api.EncryptionKey.Rekey(ctx); err != nil {
Expand All @@ -88,10 +88,10 @@ func updateEncryptionKey(ctx context.Context, data *schema.ResourceData, meta in
}
}

return readEncryptionKey(ctx, data, meta)
return readEncryptionKeyManager(ctx, data, meta)
}

func readEncryptionKey(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
func readEncryptionKeyManager(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
api := meta.(*config.Config).GetAPI()

encryptionKeys, err := api.EncryptionKey.List(ctx)
Expand All @@ -104,6 +104,6 @@ func readEncryptionKey(ctx context.Context, data *schema.ResourceData, meta inte
return diag.FromErr(data.Set("encryption_keys", flattenEncryptionKeys(encryptionKeys.Keys)))
}

func deleteEncryptionKey(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics {
func deleteEncryptionKeyManager(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics {
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package encryptionkey_test
package encryptionkeymanager_test

import (
"fmt"
Expand All @@ -14,28 +14,28 @@ import (
"github.com/auth0/terraform-provider-auth0/internal/acctest"
)

const testAccEncryptionKeyCreate = `
resource "auth0_encryption_key" "my_key" { }
const testAccEncryptionKeyManagerCreate = `
resource "auth0_encryption_key_manager" "my_key_manager" { }
`

const testAccEncryptionKeyFirstRotation = `
resource "auth0_encryption_key" "my_key" {
const testAccEncryptionKeyManagerFirstRotation = `
resource "auth0_encryption_key_manager" "my_key_manager" {
key_rotation_id = "initial_value"
}
`

const testAccEncryptionKeySecondRotation = `
resource "auth0_encryption_key" "my_key" {
const testAccEncryptionKeyManagerSecondRotation = `
resource "auth0_encryption_key_manager" "my_key_manager" {
key_rotation_id = "changed_value"
}
`

const testAccEncryptionKeyUnsetRotation = `
resource "auth0_encryption_key" "my_key" {
const testAccEncryptionKeyManagerUnsetRotation = `
resource "auth0_encryption_key_manager" "my_key_manager" {
}
`

func TestAccEncryptionKey(t *testing.T) {
func TestAccEncryptionKeyManager(t *testing.T) {
initialKey := make(map[string]string)
firstRotationKey := make(map[string]string)
secondRotationKey := make(map[string]string)
Expand All @@ -44,10 +44,10 @@ func TestAccEncryptionKey(t *testing.T) {
acctest.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
Config: testAccEncryptionKeyCreate,
Config: testAccEncryptionKeyManagerCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("auth0_encryption_key.my_key", "encryption_keys.#", regexp.MustCompile("^[1-9][0-9]*")),
extractActiveKey("auth0_encryption_key.my_key", "encryption_keys", "tenant-master-key", &initialKey),
resource.TestMatchResourceAttr("auth0_encryption_key_manager.my_key_manager", "encryption_keys.#", regexp.MustCompile("^[1-9][0-9]*")),
extractActiveKey("auth0_encryption_key_manager.my_key_manager", "encryption_keys", "tenant-master-key", &initialKey),
func(_ *terraform.State) error {
keyID, ok := initialKey["key_id"]
assert.True(t, ok && len(keyID) > 0, "key_id should exist")
Expand All @@ -65,10 +65,10 @@ func TestAccEncryptionKey(t *testing.T) {
),
},
{
Config: testAccEncryptionKeyFirstRotation,
Config: testAccEncryptionKeyManagerFirstRotation,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("auth0_encryption_key.my_key", "encryption_keys.#", regexp.MustCompile("^[1-9][0-9]*")),
extractActiveKey("auth0_encryption_key.my_key", "encryption_keys", "tenant-master-key", &firstRotationKey),
resource.TestMatchResourceAttr("auth0_encryption_key_manager.my_key_manager", "encryption_keys.#", regexp.MustCompile("^[1-9][0-9]*")),
extractActiveKey("auth0_encryption_key_manager.my_key_manager", "encryption_keys", "tenant-master-key", &firstRotationKey),
func(_ *terraform.State) error {
keyID, ok := firstRotationKey["key_id"]
assert.True(t, ok && len(keyID) > 0, "key_id should exist")
Expand All @@ -87,10 +87,10 @@ func TestAccEncryptionKey(t *testing.T) {
),
},
{
Config: testAccEncryptionKeySecondRotation,
Config: testAccEncryptionKeyManagerSecondRotation,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("auth0_encryption_key.my_key", "encryption_keys.#", regexp.MustCompile("^[1-9][0-9]*")),
extractActiveKey("auth0_encryption_key.my_key", "encryption_keys", "tenant-master-key", &secondRotationKey),
resource.TestMatchResourceAttr("auth0_encryption_key_manager.my_key_manager", "encryption_keys.#", regexp.MustCompile("^[1-9][0-9]*")),
extractActiveKey("auth0_encryption_key_manager.my_key_manager", "encryption_keys", "tenant-master-key", &secondRotationKey),
func(_ *terraform.State) error {
keyID, ok := secondRotationKey["key_id"]
assert.True(t, ok && len(keyID) > 0, "key_id should exist")
Expand All @@ -109,10 +109,10 @@ func TestAccEncryptionKey(t *testing.T) {
),
},
{
Config: testAccEncryptionKeyUnsetRotation,
Config: testAccEncryptionKeyManagerUnsetRotation,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("auth0_encryption_key.my_key", "encryption_keys.#", regexp.MustCompile("^[1-9][0-9]*")),
extractActiveKey("auth0_encryption_key.my_key", "encryption_keys", "tenant-master-key", &unsetRotationKey),
resource.TestMatchResourceAttr("auth0_encryption_key_manager.my_key_manager", "encryption_keys.#", regexp.MustCompile("^[1-9][0-9]*")),
extractActiveKey("auth0_encryption_key_manager.my_key_manager", "encryption_keys", "tenant-master-key", &unsetRotationKey),
func(_ *terraform.State) error {
keyID, ok := unsetRotationKey["key_id"]
assert.True(t, ok && len(keyID) > 0, "key_id should exist")
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/auth0/terraform-provider-auth0/internal/auth0/connection"
"github.com/auth0/terraform-provider-auth0/internal/auth0/customdomain"
"github.com/auth0/terraform-provider-auth0/internal/auth0/email"
"github.com/auth0/terraform-provider-auth0/internal/auth0/encryptionkey"
"github.com/auth0/terraform-provider-auth0/internal/auth0/encryptionkeymanager"
"github.com/auth0/terraform-provider-auth0/internal/auth0/guardian"
"github.com/auth0/terraform-provider-auth0/internal/auth0/hook"
"github.com/auth0/terraform-provider-auth0/internal/auth0/logstream"
Expand Down Expand Up @@ -108,7 +108,7 @@ func New() *schema.Provider {
"auth0_custom_domain_verification": customdomain.NewVerificationResource(),
"auth0_email_provider": email.NewResource(),
"auth0_email_template": email.NewTemplateResource(),
"auth0_encryption_key": encryptionkey.NewEncryptionKeyResource(),
"auth0_encryption_key_manager": encryptionkeymanager.NewEncryptionKeyManagerResource(),
"auth0_guardian": guardian.NewResource(),
"auth0_hook": hook.NewResource(),
"auth0_log_stream": logstream.NewResource(),
Expand Down
Loading

0 comments on commit 3c2d16f

Please sign in to comment.