Skip to content
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

feat: do not save imported state to statefile #589

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions spacelift/resource_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" +
Expand All @@ -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"] = ""
Apollorion marked this conversation as resolved.
Show resolved Hide resolved
return rawState, nil
},
},
},

Schema: map[string]*schema.Schema{
"administrative": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -662,6 +685,7 @@ func resourceStackCreate(ctx context.Context, d *schema.ResourceData, meta inter
return diag.Errorf(`"import_state" requires "manage_state" to be true`)
} else if ok {
stateContent = content.(string)
d.Set("import_state", "")
Apollorion marked this conversation as resolved.
Show resolved Hide resolved
}

path, ok := d.GetOk("import_state_file")
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
Loading