From 0b82070b30a5a3dee4a1d0f459e926dbc7f24181 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 | 26 ++++++++++++++++++++++++++ spacelift/resource_stack_test.go | 21 +++++++++++++++++++++ spacelift/type_conversions.go | 1 + 3 files changed, 48 insertions(+) diff --git a/spacelift/resource_stack.go b/spacelift/resource_stack.go index 20372a9c..2d385de1 100644 --- a/spacelift/resource_stack.go +++ b/spacelift/resource_stack.go @@ -17,6 +17,16 @@ 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 +44,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 +428,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..da9194c2 100644 --- a/spacelift/resource_stack_test.go +++ b/spacelift/resource_stack_test.go @@ -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 diff --git a/spacelift/type_conversions.go b/spacelift/type_conversions.go index aae43514..c543dc0e 100644 --- a/spacelift/type_conversions.go +++ b/spacelift/type_conversions.go @@ -3,6 +3,7 @@ package spacelift import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/shurcooL/graphql" + "github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/structs" )