-
Notifications
You must be signed in to change notification settings - Fork 109
Changed volume encryption to enabled by default. #2139
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
Open
akalcosmin
wants to merge
16
commits into
linode:dev
Choose a base branch
from
akalcosmin:volume_encryption_enabled
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ae0ab01
Changed volume encryption to enabled by default.
akalcosmin 1a29c06
Merge branch 'dev' into volume_encryption_enabled
akalcosmin 20e3974
Tests for volume encryption setting
tyakin-akamai 9676f7a
Merge branch 'dev' into volume_encryption_enabled
akalcosmin 1b0a4b5
go fmt fixes
tyakin-akamai 3ebf638
tests(volume): fix comment to reference DataWithBlockStorageEncryptio…
tyakin-akamai d57a022
When encryption is omitted, New volumes in regions supporting “Block …
tyakin-akamai 30ebc21
volume: default encryption to "enabled" on create; show in plan
tyakin-akamai 5e297ff
apply golangci-lint fmt (gci/gofumpt/goimports) and fix tests formatting
tyakin-akamai 651eb11
Add volume encryption check to smoke test and drop redundant case
tyakin-akamai 5751d4c
Consolidate volume encryption acceptance tests into resource_test.go
tyakin-akamai a9b73c8
tidy schema comments
tyakin-akamai 81f88df
drop DS additions
tyakin-akamai 65500c7
Fix data source test assertion
zliang-akamai 4e03a0a
Rename test files
zliang-akamai 818835b
Merge branch 'dev' into volume_encryption_enabled
zliang-akamai 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 hidden or 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 hidden or 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 @@ | ||
| package volume | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
| ) | ||
|
|
||
| // defaultEnabledOnCreate is a String plan modifier that sets the planned value to | ||
| // "enabled" during create when the attribute is omitted (null/unknown). | ||
| // It does nothing on updates (when a prior state value exists). | ||
| // | ||
| // This keeps the plan consistent with Create() behavior without affecting updates, | ||
| // where UseStateForUnknown preserves the existing state when the field is omitted. | ||
| type defaultEnabledOnCreate struct{} | ||
|
|
||
| func DefaultEnabledOnCreate() planmodifier.String { return defaultEnabledOnCreate{} } | ||
|
|
||
| func (m defaultEnabledOnCreate) Description(ctx context.Context) string { | ||
| return "Defaults to \"enabled\" on create when encryption is omitted" | ||
| } | ||
|
|
||
| func (m defaultEnabledOnCreate) MarkdownDescription(ctx context.Context) string { | ||
| return m.Description(ctx) | ||
| } | ||
|
|
||
| func (m defaultEnabledOnCreate) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { | ||
| // If there is a prior state value, this is an update; do nothing. | ||
| if !req.StateValue.IsNull() && !req.StateValue.IsUnknown() { | ||
| return | ||
| } | ||
| // Create path: if the user omitted encryption (null/unknown), set planned value to "enabled". | ||
| if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { | ||
| resp.PlanValue = types.StringValue("enabled") | ||
| } | ||
| } |
This file contains hidden or 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,152 @@ | ||
| //go:build integration || volume | ||
|
|
||
| package volume_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-testing/terraform" | ||
| "github.com/linode/linodego" | ||
| "github.com/linode/terraform-provider-linode/v3/linode/acceptance" | ||
| "github.com/linode/terraform-provider-linode/v3/linode/volume/tmpl" | ||
| ) | ||
|
|
||
| // Default encryption (omitted) should be enabled (provider derives default at create-time) | ||
| func TestAccResourceVolume_defaultEncryptionEnabled_Derived(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| volumeName := acctest.RandomWithPrefix("tf_test") | ||
| resName := "linode_volume.foobar" | ||
|
|
||
| // Choose a random core region without checking capabilities | ||
| targetRegion, err := acceptance.GetRandomRegionWithCaps(nil, "core") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| volume := linodego.Volume{} | ||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { acceptance.PreCheck(t) }, | ||
| ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, | ||
| CheckDestroy: acceptance.CheckVolumeDestroy, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| // Basic template omits encryption | ||
| Config: tmpl.Basic(t, volumeName, targetRegion), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| acceptance.CheckVolumeExists(resName, &volume), | ||
| resource.TestCheckResourceAttr(resName, "region", targetRegion), | ||
| resource.TestCheckResourceAttr(resName, "encryption", "enabled"), | ||
zliang-akamai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| // Explicit encryption enabled (resource test) | ||
| func TestAccResourceVolume_encryptionExplicitEnabled(t *testing.T) { | ||
zliang-akamai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| t.Parallel() | ||
|
|
||
| volumeName := acctest.RandomWithPrefix("tf_test") | ||
| resName := "linode_volume.foobar" | ||
|
|
||
| // Choose a random core region without checking capabilities | ||
| targetRegion, err := acceptance.GetRandomRegionWithCaps(nil, "core") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| volume := linodego.Volume{} | ||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { acceptance.PreCheck(t) }, | ||
| ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, | ||
| CheckDestroy: acceptance.CheckVolumeDestroy, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: tmpl.DataWithBlockStorageEncryption(t, volumeName, targetRegion), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| acceptance.CheckVolumeExists(resName, &volume), | ||
| resource.TestCheckResourceAttr(resName, "encryption", "enabled"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| // Explicit encryption disabled (resource test) | ||
| func TestAccResourceVolume_encryptionExplicitDisabled(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| volumeName := acctest.RandomWithPrefix("tf_test") | ||
| resName := "linode_volume.foobar" | ||
|
|
||
| // Choose a random core region without checking capabilities | ||
| targetRegion, err := acceptance.GetRandomRegionWithCaps(nil, "core") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| volume := linodego.Volume{} | ||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { acceptance.PreCheck(t) }, | ||
| ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, | ||
| CheckDestroy: acceptance.CheckVolumeDestroy, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: tmpl.DataWithBlockStorageEncryptionDisabled(t, volumeName, targetRegion), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| acceptance.CheckVolumeExists(resName, &volume), | ||
| resource.TestCheckResourceAttr(resName, "encryption", "disabled"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| // Changing encryption forces replacement (verify ID changes) | ||
| func TestAccResourceVolume_encryptionChangeForcesReplace(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| volumeName := acctest.RandomWithPrefix("tf_test") | ||
| resName := "linode_volume.foobar" | ||
|
|
||
| targetRegion, err := acceptance.GetRandomRegionWithCaps(nil, "core") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| var v linodego.Volume | ||
| var firstID int | ||
|
|
||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { acceptance.PreCheck(t) }, | ||
| ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories, | ||
| CheckDestroy: acceptance.CheckVolumeDestroy, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: tmpl.DataWithBlockStorageEncryptionDisabled(t, volumeName, targetRegion), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| acceptance.CheckVolumeExists(resName, &v), | ||
| resource.TestCheckResourceAttr(resName, "encryption", "disabled"), | ||
| func(_ *terraform.State) error { firstID = v.ID; return nil }, | ||
| ), | ||
| }, | ||
| { | ||
| Config: tmpl.DataWithBlockStorageEncryption(t, volumeName, targetRegion), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| acceptance.CheckVolumeExists(resName, &v), | ||
| resource.TestCheckResourceAttr(resName, "encryption", "enabled"), | ||
| func(_ *terraform.State) error { | ||
| if v.ID == firstID { | ||
| return fmt.Errorf("expected replacement, ID unchanged: %d", v.ID) | ||
| } | ||
| return nil | ||
| }, | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| //go:build unit | ||
|
|
||
| package volume | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // test that guards the schema for the encryption attribute. | ||
| func TestEncryptionAttribute_HasDefaultAndRequiresReplace(t *testing.T) { | ||
| t.Helper() | ||
|
|
||
| attrRaw, ok := frameworkResourceSchema.Attributes["encryption"] | ||
| require.True(t, ok, "encryption attribute must exist in schema") | ||
|
|
||
| attr, ok := attrRaw.(schema.StringAttribute) | ||
| require.True(t, ok, "encryption must be a StringAttribute") | ||
|
|
||
| // Should be Optional + Computed with no schema default; provider preserves state when omitted. | ||
| require.True(t, attr.Optional, "encryption should be Optional") | ||
| require.True(t, attr.Computed, "encryption should be Computed") | ||
| require.Nil(t, attr.Default, "encryption should not have a schema default") | ||
|
|
||
| // Must preserve state when config omits the field. | ||
| expectedUseStateType := reflect.TypeOf(stringplanmodifier.UseStateForUnknown()) | ||
| foundUseState := false | ||
| for _, pm := range attr.PlanModifiers { | ||
| if reflect.TypeOf(pm) == expectedUseStateType { | ||
| foundUseState = true | ||
| break | ||
| } | ||
| } | ||
| require.True(t, foundUseState, "encryption should have UseStateForUnknown plan modifier") | ||
|
|
||
| // Must require replacement when changed. | ||
| expectedReplaceType := reflect.TypeOf(stringplanmodifier.RequiresReplace()) | ||
| foundReplace := false | ||
| for _, pm := range attr.PlanModifiers { | ||
| if reflect.TypeOf(pm) == expectedReplaceType { | ||
| foundReplace = true | ||
| break | ||
| } | ||
| } | ||
| require.True(t, foundReplace, "encryption should have a RequiresReplace plan modifier") | ||
|
|
||
| // Should show default "enabled" on create when omitted. | ||
| expectedDefaultOnCreateType := reflect.TypeOf(DefaultEnabledOnCreate()) | ||
| foundDefaultOnCreate := false | ||
| for _, pm := range attr.PlanModifiers { | ||
| if reflect.TypeOf(pm) == expectedDefaultOnCreateType { | ||
| foundDefaultOnCreate = true | ||
| break | ||
| } | ||
| } | ||
| require.True(t, foundDefaultOnCreate, "encryption should have DefaultEnabledOnCreate plan modifier") | ||
|
|
||
| // Should have validators (e.g., OneOf("enabled","disabled")). We don't assert exact type, just presence. | ||
| require.NotEmpty(t, attr.Validators, "encryption should have validators (e.g., OneOf)") | ||
| } |
14 changes: 14 additions & 0 deletions
14
linode/volume/tmpl/data_with_block_storage_encryption_disabled.gotf
This file contains hidden or 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,14 @@ | ||
| {{ define "volume_data_with_block_storage_encryption_disabled" }} | ||
|
|
||
| resource "linode_volume" "foobar" { | ||
| label = "{{.Label}}" | ||
| region = "{{ .Region }}" | ||
| tags = ["tf_test"] | ||
| encryption = "disabled" | ||
| } | ||
|
|
||
| data "linode_volume" "foobar" { | ||
| id = "${linode_volume.foobar.id}" | ||
| } | ||
|
|
||
| {{ end }} |
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.
Uh oh!
There was an error while loading. Please reload this page.