diff --git a/.changelog/1093.txt b/.changelog/1093.txt new file mode 100644 index 000000000..3af303704 --- /dev/null +++ b/.changelog/1093.txt @@ -0,0 +1,3 @@ +```release-note:bug +Waypoint: fix where using the deprecated terraform_cloud_workspace_details.name field could cause an error. +``` diff --git a/internal/provider/waypoint/resource_waypoint_template.go b/internal/provider/waypoint/resource_waypoint_template.go index d5c51e5d6..34a384fdc 100644 --- a/internal/provider/waypoint/resource_waypoint_template.go +++ b/internal/provider/waypoint/resource_waypoint_template.go @@ -270,12 +270,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques } tfProjID := plan.TerraformProjectID.ValueString() - tfWsName := plan.TerraformCloudWorkspace.Name.ValueString() - if tfWsName == "" { - // NOTE: this field is optional anyways, so if its unset, lets just use - // the template name for it. - tfWsName = plan.Name.ValueString() - } + tfWsName := plan.Name.ValueString() tfWsDetails := &waypoint_models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: tfWsName, ProjectID: tfProjID, @@ -332,11 +327,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques plan.TerraformNoCodeModuleSource = types.StringValue(appTemplate.ModuleSource) if appTemplate.TerraformCloudWorkspaceDetails != nil { - tfcWorkspace := &tfcWorkspace{ - Name: types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.Name), - TerraformProjectID: types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.ProjectID), - } - plan.TerraformCloudWorkspace = tfcWorkspace + plan.TerraformProjectID = types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.ProjectID) } labels, diags := types.ListValueFrom(ctx, types.StringType, appTemplate.Labels) @@ -447,11 +438,7 @@ func (r *TemplateResource) Read(ctx context.Context, req resource.ReadRequest, r data.TerraformNoCodeModuleSource = types.StringValue(appTemplate.ModuleSource) if appTemplate.TerraformCloudWorkspaceDetails != nil { - tfcWorkspace := &tfcWorkspace{ - Name: types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.Name), - TerraformProjectID: types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.ProjectID), - } - data.TerraformCloudWorkspace = tfcWorkspace + data.TerraformProjectID = types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.ProjectID) } data.TerraformVariableOptions, err = readVarOpts(ctx, appTemplate.VariableOptions, &resp.Diagnostics) @@ -540,12 +527,7 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques } tfProjID := plan.TerraformProjectID.ValueString() - tfWsName := plan.TerraformCloudWorkspace.Name.ValueString() - if tfWsName == "" { - // NOTE: this field is optional anyways, so if its unset, lets just use - // the template name for it. - tfWsName = plan.Name.ValueString() - } + tfWsName := plan.Name.ValueString() tfWsDetails := &waypoint_models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: tfWsName, ProjectID: tfProjID, @@ -602,6 +584,10 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques plan.Summary = types.StringValue(appTemplate.Summary) plan.TerraformNoCodeModuleSource = types.StringValue(appTemplate.ModuleSource) + if appTemplate.TerraformCloudWorkspaceDetails != nil { + plan.TerraformProjectID = types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.ProjectID) + } + labels, diags := types.ListValueFrom(ctx, types.StringType, appTemplate.Labels) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -609,14 +595,6 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques } plan.Labels = labels - if appTemplate.TerraformCloudWorkspaceDetails != nil { - tfcWorkspace := &tfcWorkspace{ - Name: types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.Name), - TerraformProjectID: types.StringValue(appTemplate.TerraformCloudWorkspaceDetails.ProjectID), - } - plan.TerraformCloudWorkspace = tfcWorkspace - } - plan.Description = types.StringValue(appTemplate.Description) if appTemplate.Description == "" { plan.Description = types.StringNull()