Skip to content

Commit

Permalink
feat: do not save imported state to statefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollorion committed Nov 25, 2024
1 parent 0b0d800 commit 4a6bffd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spacelift/resource_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" +
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions spacelift/resource_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a6bffd

Please sign in to comment.