Skip to content

Commit

Permalink
Merge pull request #383 from Juniper/bug/382-tag-state-churn
Browse files Browse the repository at this point in the history
Fix tag state churn when `description` is omitted
  • Loading branch information
chrismarget-j authored Oct 2, 2023
2 parents f7fb175 + ef49bdd commit 6421c31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apstra/design/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func (o Tag) AttrTypes() map[string]attr.Type {
}
}

func (o *Tag) LoadApiData(_ context.Context, in *apstra.DesignTagData, _ *diag.Diagnostics) {
func (o *Tag) LoadApiData(ctx context.Context, in *apstra.DesignTagData, diags *diag.Diagnostics) {
o.Name = types.StringValue(in.Label)
o.Description = types.StringValue(in.Description)
o.Description = utils.StringValueOrNull(ctx, in.Description, diags)
}

func (o *Tag) Request(_ context.Context, _ *diag.Diagnostics) *apstra.DesignTagRequest {
Expand Down
9 changes: 3 additions & 6 deletions apstra/resource_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,17 @@ func (o *resourceTag) Read(ctx context.Context, req resource.ReadRequest, resp *
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("error reading Tag", err.Error())
resp.Diagnostics.AddError("failed reading Tag", err.Error())
return
}

// create new state object
var newState design.Tag
newState.Id = types.StringValue(string(t.Id))
newState.LoadApiData(ctx, t.Data, &resp.Diagnostics)
state.LoadApiData(ctx, t.Data, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

// set state
resp.Diagnostics.Append(resp.State.Set(ctx, &newState)...)
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

// Update resource
Expand Down

0 comments on commit 6421c31

Please sign in to comment.