Skip to content

Commit

Permalink
[Waypoint] Stop using the deprecated terraform cloud workspace name f…
Browse files Browse the repository at this point in the history
…ield (#1093)

We will stop using the deprecated terraform cloud workspace name field to avoid a segmentation fault when it is not set by the user
  • Loading branch information
HenryEstberg authored Sep 17, 2024
1 parent 6a49311 commit c6e6394
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .changelog/1093.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Waypoint: fix where using the deprecated terraform_cloud_workspace_details.name field could cause an error.
```
38 changes: 8 additions & 30 deletions internal/provider/waypoint/resource_waypoint_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -602,21 +584,17 @@ 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() {
return
}
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()
Expand Down

0 comments on commit c6e6394

Please sign in to comment.