Skip to content

Commit

Permalink
Update pipeline definition resource import state functionality (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
yosuke-oka authored Mar 5, 2025
1 parent 3b0e363 commit a0bd26a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions internal/provider/pipeline_definition_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
Expand Down Expand Up @@ -301,5 +300,21 @@ func (r *pipelineDefinitionResource) ImportState(
return
}

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), id)...)
en, err := r.client.GetPipelineDefinition(id)
if err != nil {
resp.Diagnostics.AddError(
"Importing pipeline definition",
fmt.Sprintf("Unable to retrieve pipeline definition, got error: %s", err),
)
return
}

keys := map[int64]types.String{}
for _, t := range en.Tasks {
keys[t.TaskIdentifier] = types.StringValue(strconv.FormatInt(t.TaskIdentifier, 10))
}

newState := pdm.NewPipelineDefinition(en, keys, &pdm.PipelineDefinition{})

resp.Diagnostics.Append(resp.State.Set(ctx, newState)...)
}

0 comments on commit a0bd26a

Please sign in to comment.