Skip to content

Commit 604bb24

Browse files
committed
check if tags not set
1 parent 516409f commit 604bb24

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

internal/provider/resource_tfe_workspace_settings.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -513,20 +513,21 @@ func (r *workspaceSettings) updateSettings(ctx context.Context, data *modelWorks
513513
updateOptions.ExecutionMode = tfe.String("remote")
514514
}
515515

516-
tags := data.Tags.Elements()
517-
for key, val := range tags {
518-
if strVal, ok := val.(types.String); ok && !strVal.IsNull() {
519-
updateOptions.TagBindings = append(updateOptions.TagBindings, &tfe.TagBinding{
520-
Key: key,
521-
Value: strVal.ValueString(),
522-
})
523-
}
524-
}
525-
526-
if len(tags) == 0 {
527-
err := r.config.Client.Workspaces.DeleteAllTagBindings(ctx, workspaceID)
528-
if err != nil {
529-
return fmt.Errorf("error removing tag bindings from workspace %s: %w", workspaceID, err)
516+
if !data.Tags.IsNull() && !data.Tags.IsUnknown() {
517+
tags := data.Tags.Elements()
518+
if len(tags) == 0 {
519+
if err := r.config.Client.Workspaces.DeleteAllTagBindings(ctx, workspaceID); err != nil {
520+
return fmt.Errorf("error removing tag bindings from workspace %s: %w", workspaceID, err)
521+
}
522+
} else {
523+
for key, val := range tags {
524+
if strVal, ok := val.(types.String); ok && !strVal.IsNull() && !strVal.IsUnknown() {
525+
updateOptions.TagBindings = append(updateOptions.TagBindings, &tfe.TagBinding{
526+
Key: key,
527+
Value: strVal.ValueString(),
528+
})
529+
}
530+
}
530531
}
531532
}
532533

0 commit comments

Comments
 (0)