From 05edc65f546de91ef6a8d8b2186526bf76d40706 Mon Sep 17 00:00:00 2001 From: apollorion Date: Mon, 25 Nov 2024 12:55:23 -0500 Subject: [PATCH] feat: do not save imported state to statefile --- spacelift/resource_stack.go | 27 +++++++++++++++++++++++++++ spacelift/resource_stack_test.go | 25 +++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/spacelift/resource_stack.go b/spacelift/resource_stack.go index 20372a9c..93739add 100644 --- a/spacelift/resource_stack.go +++ b/spacelift/resource_stack.go @@ -17,6 +17,17 @@ import ( "github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/validations" ) +func resourceStackResourceV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "import_state": { + Type: schema.TypeString, + }, + }, + } +} + + func resourceStack() *schema.Resource { return &schema.Resource{ Description: "" + @@ -34,6 +45,19 @@ func resourceStack() *schema.Resource { StateContext: resourceStackImport, }, + SchemaVersion: 1, + + StateUpgraders: []schema.StateUpgrader{ + { + Version: 0, + Type: resourceStackResourceV0().CoreConfigSchema().ImpliedType(), + Upgrade: func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error){ + rawState["import_state"] = "" + return rawState, nil + }, + }, + }, + Schema: map[string]*schema.Schema{ "administrative": { Type: schema.TypeBool, @@ -405,6 +429,9 @@ func resourceStack() *schema.Resource { Optional: true, DiffSuppressFunc: ignoreOnceCreated, Sensitive: true, + StateFunc: func(v interface{}) string { + return "" + }, }, "import_state_file": { Type: schema.TypeString, diff --git a/spacelift/resource_stack_test.go b/spacelift/resource_stack_test.go index a51e0c18..16bfd27f 100644 --- a/spacelift/resource_stack_test.go +++ b/spacelift/resource_stack_test.go @@ -331,7 +331,7 @@ func TestStackResource(t *testing.T) { name = "labelled-module-%s" branch = "master" labels = [] - repository = "terraform-bacon-tasty" + repository = "demo" }`, randomID), Check: Resource( "spacelift_stack.test", @@ -1482,7 +1482,7 @@ func TestStackResourceSpace(t *testing.T) { name = "labelled-module-%s" branch = "master" labels = [] - repository = "terraform-bacon-tasty" + repository = "demo" }`, randomID), Check: Resource( "spacelift_stack.test", @@ -1637,6 +1637,27 @@ func TestStackResourceSpace(t *testing.T) { }, }) }) + + t.Run("with import_state", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testSteps(t, []resource.TestStep{ + { + Config: fmt.Sprintf(` + resource "spacelift_stack" "state_import" { + branch = "master" + name = "Provider test stack workflow_tool default %s" + project_root = "root" + repository = "demo" + import_state = "{}" + } + `, randomID), + Check: Resource( + "spacelift_stack.state_import", + Attribute("import_state", Equals("")), + ), + }, + }) + }) } // getConfig returns a stack config with injected vendor config