From 15c673e0f23c2ff2c91697271e8a60704c73d767 Mon Sep 17 00:00:00 2001 From: paladin-devops <83741749+paladin-devops@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:38:31 -0400 Subject: [PATCH] Remove module version from Waypoint templates + add-ons. --- go.mod | 2 +- go.sum | 4 +- .../waypoint/data_source_waypoint_add_on.go | 29 ++------ .../data_source_waypoint_add_on_definition.go | 15 ++--- .../waypoint/data_source_waypoint_template.go | 29 ++------ .../waypoint/resource_waypoint_add_on.go | 67 ++----------------- .../resource_waypoint_add_on_definition.go | 60 ++++------------- ...esource_waypoint_add_on_definition_test.go | 5 +- .../waypoint/resource_waypoint_add_on_test.go | 30 ++------- .../resource_waypoint_application_test.go | 10 +-- .../waypoint/resource_waypoint_template.go | 63 ++++------------- .../resource_waypoint_template_test.go | 10 +-- 12 files changed, 59 insertions(+), 265 deletions(-) diff --git a/go.mod b/go.mod index d1d8c34e3..7dc8c8e53 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/go-version v1.6.0 - github.com/hashicorp/hcp-sdk-go v0.98.0 + github.com/hashicorp/hcp-sdk-go v0.99.1-0.20240620191200-f4b257874e66 github.com/hashicorp/terraform-plugin-docs v0.18.0 github.com/hashicorp/terraform-plugin-framework v1.5.0 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 diff --git a/go.sum b/go.sum index 17b912920..f0dcdf563 100644 --- a/go.sum +++ b/go.sum @@ -120,8 +120,8 @@ github.com/hashicorp/hc-install v0.6.2 h1:V1k+Vraqz4olgZ9UzKiAcbman9i9scg9GgSt/U github.com/hashicorp/hc-install v0.6.2/go.mod h1:2JBpd+NCFKiHiu/yYCGaPyPHhZLxXTpz8oreHa/a3Ps= github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI= github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= -github.com/hashicorp/hcp-sdk-go v0.98.0 h1:DKLbGJcP9tCR4EBme6npvcigcRuvma6WCyH1ApZuNaU= -github.com/hashicorp/hcp-sdk-go v0.98.0/go.mod h1:vQ4fzdL1AmhIAbCw+4zmFe5Hbpajj3NvRWkJoVuxmAk= +github.com/hashicorp/hcp-sdk-go v0.99.1-0.20240620191200-f4b257874e66 h1:I0Y7+rTgxWr7khAFHX4UZq6CSm3xPV32ymqOE6g3mVw= +github.com/hashicorp/hcp-sdk-go v0.99.1-0.20240620191200-f4b257874e66/go.mod h1:vQ4fzdL1AmhIAbCw+4zmFe5Hbpajj3NvRWkJoVuxmAk= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.20.0 h1:DIZnPsqzPGuUnq6cH8jWcPunBfY+C+M8JyYF3vpnuEo= diff --git a/internal/provider/waypoint/data_source_waypoint_add_on.go b/internal/provider/waypoint/data_source_waypoint_add_on.go index bd06c0674..9327bef2c 100644 --- a/internal/provider/waypoint/data_source_waypoint_add_on.go +++ b/internal/provider/waypoint/data_source_waypoint_add_on.go @@ -59,7 +59,7 @@ type AddOnDataSourceModel struct { DefinitionID types.String `tfsdk:"definition_id"` OutputValues types.List `tfsdk:"output_values"` - TerraformNoCodeModule types.Object `tfsdk:"terraform_no_code_module"` + TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"` InputVars types.Set `tfsdk:"input_variables"` } @@ -123,19 +123,9 @@ func (d *DataSourceAddOn) Schema(ctx context.Context, req datasource.SchemaReque Computed: true, Description: "The ID of the Application that this Add-on is created for.", }, - "terraform_no_code_module": &schema.SingleNestedAttribute{ + "terraform_no_code_module_source": schema.StringAttribute{ Computed: true, - Description: "Terraform Cloud no-code Module details.", - Attributes: map[string]schema.Attribute{ - "source": &schema.StringAttribute{ - Computed: true, - Description: "Terraform Cloud no-code Module Source", - }, - "version": &schema.StringAttribute{ - Computed: true, - Description: "Terraform Cloud no-code Module Version", - }, - }, + Description: "The Terraform module source for the Add-on.", }, "status": schema.Int64Attribute{ Computed: true, @@ -245,6 +235,7 @@ func (d *DataSourceAddOn) Read(ctx context.Context, req datasource.ReadRequest, } state.Summary = types.StringValue(addOn.Summary) + state.TerraformNoCodeModuleSource = types.StringValue(addOn.ModuleSource) labels, diags := types.ListValueFrom(ctx, types.StringType, addOn.Labels) resp.Diagnostics.Append(diags...) @@ -256,18 +247,6 @@ func (d *DataSourceAddOn) Read(ctx context.Context, req datasource.ReadRequest, } state.Labels = labels - if addOn.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(addOn.TerraformNocodeModule.Source), - Version: types.StringValue(addOn.TerraformNocodeModule.Version), - } - state.TerraformNoCodeModule, diags = types.ObjectValueFrom(ctx, tfcNoCode.attrTypes(), tfcNoCode) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - } - // set plan.description if it's not null or addOn.description is not empty state.Description = types.StringValue(addOn.Description) if addOn.Description == "" { diff --git a/internal/provider/waypoint/data_source_waypoint_add_on_definition.go b/internal/provider/waypoint/data_source_waypoint_add_on_definition.go index e345bc793..7fbd7387d 100644 --- a/internal/provider/waypoint/data_source_waypoint_add_on_definition.go +++ b/internal/provider/waypoint/data_source_waypoint_add_on_definition.go @@ -44,9 +44,9 @@ type DataSourceAddOnDefinitionModel struct { Description types.String `tfsdk:"description"` ReadmeMarkdownTemplate types.String `tfsdk:"readme_markdown_template"` - TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` - TerraformNoCodeModule *tfcNoCodeModule `tfsdk:"terraform_no_code_module"` - TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"` + TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` + TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"` + TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"` } func NewAddOnDefinitionDataSource() datasource.DataSource { @@ -210,6 +210,7 @@ func (d *DataSourceAddOnDefinition) Read(ctx context.Context, req datasource.Rea state.OrgID = types.StringValue(client.Config.OrganizationID) state.ProjectID = types.StringValue(client.Config.ProjectID) state.Summary = types.StringValue(definition.Summary) + state.Description = types.StringValue(definition.Description) if definition.TerraformCloudWorkspaceDetails != nil { tfcWorkspace := &tfcWorkspace{ @@ -219,14 +220,6 @@ func (d *DataSourceAddOnDefinition) Read(ctx context.Context, req datasource.Rea state.TerraformCloudWorkspace = tfcWorkspace } - if definition.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(definition.TerraformNocodeModule.Source), - Version: types.StringValue(definition.TerraformNocodeModule.Version), - } - state.TerraformNoCodeModule = tfcNoCode - } - labels, diags := types.ListValueFrom(ctx, types.StringType, definition.Labels) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/internal/provider/waypoint/data_source_waypoint_template.go b/internal/provider/waypoint/data_source_waypoint_template.go index 5e3f7d15a..fbc69774f 100644 --- a/internal/provider/waypoint/data_source_waypoint_template.go +++ b/internal/provider/waypoint/data_source_waypoint_template.go @@ -44,9 +44,9 @@ type DataSourceTemplateModel struct { Description types.String `tfsdk:"description"` ReadmeMarkdownTemplate types.String `tfsdk:"readme_markdown_template"` - TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` - TerraformNoCodeModule *tfcNoCodeModule `tfsdk:"terraform_no_code_module"` - VariableOptions []*tfcVariableOption `tfsdk:"variable_options"` + TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` + TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"` + VariableOptions []*tfcVariableOption `tfsdk:"variable_options"` } func NewTemplateDataSource() datasource.DataSource { @@ -111,19 +111,9 @@ func (d *DataSourceTemplate) Schema(ctx context.Context, req datasource.SchemaRe }, }, }, - "terraform_no_code_module": &schema.SingleNestedAttribute{ + "terraform_no_code_module_source": &schema.SingleNestedAttribute{ Computed: true, - Description: "Terraform Cloud No-Code Module details", - Attributes: map[string]schema.Attribute{ - "source": &schema.StringAttribute{ - Computed: true, - Description: "No-Code Module Source", - }, - "version": &schema.StringAttribute{ - Computed: true, - Description: "No-Code Module Version", - }, - }, + Description: "Terraform No Code Module source", }, "variable_options": schema.ListNestedAttribute{ Computed: true, @@ -210,6 +200,7 @@ func (d *DataSourceTemplate) Read(ctx context.Context, req datasource.ReadReques data.OrgID = types.StringValue(client.Config.OrganizationID) data.ProjectID = types.StringValue(client.Config.ProjectID) data.Summary = types.StringValue(appTemplate.Summary) + data.TerraformNoCodeModuleSource = types.StringValue(appTemplate.ModuleSource) if appTemplate.TerraformCloudWorkspaceDetails != nil { tfcWorkspace := &tfcWorkspace{ @@ -219,14 +210,6 @@ func (d *DataSourceTemplate) Read(ctx context.Context, req datasource.ReadReques data.TerraformCloudWorkspace = tfcWorkspace } - if appTemplate.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(appTemplate.TerraformNocodeModule.Source), - Version: types.StringValue(appTemplate.TerraformNocodeModule.Version), - } - data.TerraformNoCodeModule = tfcNoCode - } - data.VariableOptions, err = readVarOpts(ctx, appTemplate.VariableOptions, &resp.Diagnostics) if err != nil { tflog.Error(ctx, err.Error()) diff --git a/internal/provider/waypoint/resource_waypoint_add_on.go b/internal/provider/waypoint/resource_waypoint_add_on.go index 9cbf26e11..96e5a65de 100644 --- a/internal/provider/waypoint/resource_waypoint_add_on.go +++ b/internal/provider/waypoint/resource_waypoint_add_on.go @@ -53,7 +53,7 @@ type AddOnResourceModel struct { DefinitionID types.String `tfsdk:"definition_id"` OutputValues types.List `tfsdk:"output_values"` - TerraformNoCodeModule types.Object `tfsdk:"terraform_no_code_module"` + TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"` InputVars types.Set `tfsdk:"add_on_input_variables"` AddOnDefinitionInputVars types.Set `tfsdk:"add_on_definition_input_variables"` @@ -75,13 +75,6 @@ func (o outputValue) attrTypes() map[string]attr.Type { } } -func (r tfcNoCodeModule) attrTypes() map[string]attr.Type { - return map[string]attr.Type{ - "source": types.StringType, - "version": types.StringType, - } -} - func (r *AddOnResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_waypoint_add_on" } @@ -148,19 +141,9 @@ func (r *AddOnResource) Schema(ctx context.Context, req resource.SchemaRequest, "Add-on Definition.", Computed: true, }, - "terraform_no_code_module": &schema.SingleNestedAttribute{ + "terraform_no_code_module_source": schema.StringAttribute{ + Description: "The Terraform No Code Module source for the Add-on.", Computed: true, - Description: "Terraform Cloud no-code Module details.", - Attributes: map[string]schema.Attribute{ - "source": &schema.StringAttribute{ - Computed: true, - Description: "Terraform Cloud no-code Module Source", - }, - "version": &schema.StringAttribute{ - Computed: true, - Description: "Terraform Cloud no-code Module Version", - }, - }, }, "definition_id": schema.StringAttribute{ Required: true, @@ -391,8 +374,9 @@ func (r *AddOnResource) Create(ctx context.Context, req resource.CreateRequest, plan.ProjectID = types.StringValue(projectID) plan.OrgID = types.StringValue(orgID) plan.Summary = types.StringValue(addOn.Summary) - plan.Description = types.StringValue(addOn.Description) + plan.TerraformNoCodeModuleSource = types.StringValue(addOn.TerraformNocodeModule.Source) + // set plan.description if it's not null or addOn.description is not empty if addOn.Description == "" { plan.Description = types.StringNull() @@ -410,21 +394,6 @@ func (r *AddOnResource) Create(ctx context.Context, req resource.CreateRequest, } plan.Labels = labels - if addOn.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{} - if addOn.TerraformNocodeModule.Source != "" { - tfcNoCode.Source = types.StringValue(addOn.TerraformNocodeModule.Source) - } - if addOn.TerraformNocodeModule.Version != "" { - tfcNoCode.Version = types.StringValue(addOn.TerraformNocodeModule.Version) - } - plan.TerraformNoCodeModule, diags = types.ObjectValueFrom(ctx, tfcNoCode.attrTypes(), tfcNoCode) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - } - // Display the reference to the Definition in the plan if addOn.Definition != nil { if addOn.Definition.ID != "" { @@ -556,6 +525,7 @@ func (r *AddOnResource) Read(ctx context.Context, req resource.ReadRequest, resp state.ProjectID = types.StringValue(projectID) state.OrgID = types.StringValue(orgID) state.Summary = types.StringValue(addOn.Summary) + state.TerraformNoCodeModuleSource = types.StringValue(addOn.TerraformNocodeModule.Source) state.Description = types.StringValue(addOn.Description) // set plan.description if it's not null or addOn.description is not empty @@ -575,18 +545,6 @@ func (r *AddOnResource) Read(ctx context.Context, req resource.ReadRequest, resp } state.Labels = labels - if addOn.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(addOn.TerraformNocodeModule.Source), - Version: types.StringValue(addOn.TerraformNocodeModule.Version), - } - state.TerraformNoCodeModule, diags = types.ObjectValueFrom(ctx, tfcNoCode.attrTypes(), tfcNoCode) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - } - state.CreatedBy = types.StringValue(addOn.CreatedBy) // If we can process status as an int64, add it to the plan @@ -717,6 +675,7 @@ func (r *AddOnResource) Update(ctx context.Context, req resource.UpdateRequest, plan.ProjectID = types.StringValue(projectID) plan.OrgID = types.StringValue(orgID) plan.Summary = types.StringValue(addOn.Summary) + plan.TerraformNoCodeModuleSource = types.StringValue(addOn.TerraformNocodeModule.Source) plan.Description = types.StringValue(addOn.Description) // set plan.description if it's not null or addOn.description is not empty @@ -736,18 +695,6 @@ func (r *AddOnResource) Update(ctx context.Context, req resource.UpdateRequest, } plan.Labels = labels - if addOn.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(addOn.TerraformNocodeModule.Source), - Version: types.StringValue(addOn.TerraformNocodeModule.Version), - } - plan.TerraformNoCodeModule, diags = types.ObjectValueFrom(ctx, tfcNoCode.attrTypes(), tfcNoCode) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - } - // Display the reference to the Definition in the plan if addOn.Definition != nil { if addOn.Definition.ID != "" { diff --git a/internal/provider/waypoint/resource_waypoint_add_on_definition.go b/internal/provider/waypoint/resource_waypoint_add_on_definition.go index b894c21ac..7f433eb57 100644 --- a/internal/provider/waypoint/resource_waypoint_add_on_definition.go +++ b/internal/provider/waypoint/resource_waypoint_add_on_definition.go @@ -46,9 +46,9 @@ type AddOnDefinitionResourceModel struct { Description types.String `tfsdk:"description"` ReadmeMarkdownTemplate types.String `tfsdk:"readme_markdown_template"` - TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` - TerraformNoCodeModule *tfcNoCodeModule `tfsdk:"terraform_no_code_module"` - TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"` + TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` + TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"` + TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"` } func (r *AddOnDefinitionResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -122,18 +122,11 @@ func (r *AddOnDefinitionResource) Schema(ctx context.Context, req resource.Schem }, }, }, - "terraform_no_code_module": &schema.SingleNestedAttribute{ + "terraform_no_code_module_source": &schema.StringAttribute{ Required: true, - Description: "Terraform Cloud no-code Module details.", - Attributes: map[string]schema.Attribute{ - "source": &schema.StringAttribute{ - Required: true, - Description: "Terraform Cloud no-code Module Source", - }, - "version": &schema.StringAttribute{ - Required: true, - Description: "Terraform Cloud no-code Module Version", - }, + Description: "Terraform No Code Module source", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, "variable_options": schema.SetNestedAttribute{ @@ -258,11 +251,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat Description: plan.Description.ValueString(), ReadmeMarkdownTemplate: readmeBytes, Labels: stringLabels, - TerraformNocodeModule: &waypointModels.HashicorpCloudWaypointTerraformNocodeModule{ - // verify these exist in the file - Source: plan.TerraformNoCodeModule.Source.ValueString(), - Version: plan.TerraformNoCodeModule.Version.ValueString(), - }, + ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(), TerraformCloudWorkspaceDetails: &waypointModels.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: plan.TerraformCloudWorkspace.Name.ValueString(), ProjectID: plan.TerraformCloudWorkspace.TerraformProjectID.ValueString(), @@ -294,6 +283,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat plan.Name = types.StringValue(addOnDefinition.Name) plan.OrgID = types.StringValue(orgID) plan.Summary = types.StringValue(addOnDefinition.Summary) + plan.TerraformNoCodeModuleSource = types.StringValue(addOnDefinition.TerraformNocodeModule.Source) plan.Description = types.StringValue(addOnDefinition.Description) // set plan.description if it's not null or addOnDefinition.description is not empty @@ -321,14 +311,6 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat plan.TerraformCloudWorkspace = tfcWorkspace } - if addOnDefinition.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(addOnDefinition.TerraformNocodeModule.Source), - Version: types.StringValue(addOnDefinition.TerraformNocodeModule.Version), - } - plan.TerraformNoCodeModule = tfcNoCode - } - plan.TerraformVariableOptions, err = readVarOpts(ctx, addOnDefinition.VariableOptions, &resp.Diagnostics) if err != nil { tflog.Error(ctx, err.Error()) @@ -382,6 +364,7 @@ func (r *AddOnDefinitionResource) Read(ctx context.Context, req resource.ReadReq state.OrgID = types.StringValue(client.Config.OrganizationID) state.ProjectID = types.StringValue(client.Config.ProjectID) state.Summary = types.StringValue(definition.Summary) + state.TerraformNoCodeModuleSource = types.StringValue(definition.TerraformNocodeModule.Source) state.Description = types.StringValue(definition.Description) // set plan.description if it's not null or addOnDefinition.description is not empty @@ -409,14 +392,6 @@ func (r *AddOnDefinitionResource) Read(ctx context.Context, req resource.ReadReq state.TerraformCloudWorkspace = tfcWorkspace } - if definition.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(definition.TerraformNocodeModule.Source), - Version: types.StringValue(definition.TerraformNocodeModule.Version), - } - state.TerraformNoCodeModule = tfcNoCode - } - state.TerraformVariableOptions, err = readVarOpts(ctx, definition.VariableOptions, &resp.Diagnostics) if err != nil { tflog.Error(ctx, err.Error()) @@ -500,11 +475,7 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat Description: plan.Description.ValueString(), ReadmeMarkdownTemplate: readmeBytes, Labels: stringLabels, - TerraformNocodeModule: &waypointModels.HashicorpCloudWaypointTerraformNocodeModule{ - // verify these exist in the file - Source: plan.TerraformNoCodeModule.Source.ValueString(), - Version: plan.TerraformNoCodeModule.Version.ValueString(), - }, + ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(), TerraformCloudWorkspaceDetails: &waypointModels.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: plan.TerraformCloudWorkspace.Name.ValueString(), ProjectID: plan.TerraformCloudWorkspace.TerraformProjectID.ValueString(), @@ -537,6 +508,7 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat plan.Name = types.StringValue(addOnDefinition.Name) plan.OrgID = types.StringValue(orgID) plan.Summary = types.StringValue(addOnDefinition.Summary) + plan.TerraformNoCodeModuleSource = types.StringValue(addOnDefinition.TerraformNocodeModule.Source) plan.Description = types.StringValue(addOnDefinition.Description) // set plan.description if it's not null or addOnDefinition.description is not empty @@ -564,14 +536,6 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat plan.TerraformCloudWorkspace = tfcWorkspace } - if addOnDefinition.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(addOnDefinition.TerraformNocodeModule.Source), - Version: types.StringValue(addOnDefinition.TerraformNocodeModule.Version), - } - plan.TerraformNoCodeModule = tfcNoCode - } - plan.TerraformVariableOptions, err = readVarOpts(ctx, addOnDefinition.VariableOptions, &resp.Diagnostics) if err != nil { tflog.Error(ctx, err.Error()) diff --git a/internal/provider/waypoint/resource_waypoint_add_on_definition_test.go b/internal/provider/waypoint/resource_waypoint_add_on_definition_test.go index 4798b0444..3721f14d1 100644 --- a/internal/provider/waypoint/resource_waypoint_add_on_definition_test.go +++ b/internal/provider/waypoint/resource_waypoint_add_on_definition_test.go @@ -142,10 +142,7 @@ resource "hcp_waypoint_add_on_definition" "test" { name = %q summary = "some summary for fun" description = "some description for fun" - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-template-starter/null" - version = "0.0.3" - } + terraform_no_code_module = "private/waypoint-tfc-testing/waypoint-template-starter/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" diff --git a/internal/provider/waypoint/resource_waypoint_add_on_test.go b/internal/provider/waypoint/resource_waypoint_add_on_test.go index 5516039d3..15d4e2cb5 100644 --- a/internal/provider/waypoint/resource_waypoint_add_on_test.go +++ b/internal/provider/waypoint/resource_waypoint_add_on_test.go @@ -190,10 +190,7 @@ resource "hcp_waypoint_template" "test" { name = "%s" summary = "some summary for fun" readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-template-starter/null" - version = "0.0.2" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" @@ -210,10 +207,7 @@ resource "hcp_waypoint_add_on_definition" "test" { name = "%s" summary = "some summary for fun" description = "some description for fun" - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-template-starter/null" - version = "0.0.2" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" @@ -233,10 +227,7 @@ resource "hcp_waypoint_template" "test" { name = "%s" summary = "some summary for fun" readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-template-starter/null" - version = "0.0.2" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" @@ -254,10 +245,7 @@ resource "hcp_waypoint_add_on_definition" "test_var_opts" { summary = "some summary for fun" description = "some description for fun" readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" - version = "0.0.1" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" @@ -318,10 +306,7 @@ resource "hcp_waypoint_template" "test" { name = "%s" summary = "some summary for fun" readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-template-starter/null" - version = "0.0.2" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" @@ -339,10 +324,7 @@ resource "hcp_waypoint_add_on_definition" "test_var_opts" { summary = "some summary for fun" description = "some description" readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" - version = "0.0.1" - } + terraform_no_code_module = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" diff --git a/internal/provider/waypoint/resource_waypoint_application_test.go b/internal/provider/waypoint/resource_waypoint_application_test.go index 2efe77060..67f88f4d1 100644 --- a/internal/provider/waypoint/resource_waypoint_application_test.go +++ b/internal/provider/waypoint/resource_waypoint_application_test.go @@ -215,10 +215,7 @@ resource "hcp_waypoint_template" "test_var_opts" { name = "%s" summary = "some summary for fun" readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" - version = "0.0.1" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" @@ -276,10 +273,7 @@ resource "hcp_waypoint_template" "test_var_opts" { name = "%s" summary = "some summary for fun" readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" - version = "0.0.1" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" diff --git a/internal/provider/waypoint/resource_waypoint_template.go b/internal/provider/waypoint/resource_waypoint_template.go index 829784408..65b4257e4 100644 --- a/internal/provider/waypoint/resource_waypoint_template.go +++ b/internal/provider/waypoint/resource_waypoint_template.go @@ -49,9 +49,9 @@ type TemplateResourceModel struct { Description types.String `tfsdk:"description"` ReadmeMarkdownTemplate types.String `tfsdk:"readme_markdown_template"` - TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` - TerraformNoCodeModule *tfcNoCodeModule `tfsdk:"terraform_no_code_module"` - TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"` + TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` + TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"` + TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"` } type tfcWorkspace struct { @@ -60,11 +60,6 @@ type tfcWorkspace struct { TerraformProjectID types.String `tfsdk:"terraform_project_id"` } -type tfcNoCodeModule struct { - Source types.String `tfsdk:"source"` - Version types.String `tfsdk:"version"` -} - type tfcVariableOption struct { Name types.String `tfsdk:"name"` VariableType types.String `tfsdk:"variable_type"` @@ -143,18 +138,11 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques }, }, }, - "terraform_no_code_module": &schema.SingleNestedAttribute{ + "terraform_no_code_module_source": schema.StringAttribute{ Required: true, - Description: "Terraform Cloud No-Code Module details", - Attributes: map[string]schema.Attribute{ - "source": &schema.StringAttribute{ - Required: true, - Description: "No-Code Module Source", - }, - "version": &schema.StringAttribute{ - Required: true, - Description: "No-Code Module Version", - }, + Description: "Source of the Terraform module", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, "variable_options": schema.SetNestedAttribute{ @@ -279,10 +267,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques Labels: strLabels, Description: plan.Description.ValueString(), ReadmeMarkdownTemplate: readmeBytes, - TerraformNocodeModule: &waypoint_models.HashicorpCloudWaypointTerraformNocodeModule{ - Source: plan.TerraformNoCodeModule.Source.ValueString(), - Version: plan.TerraformNoCodeModule.Version.ValueString(), - }, + ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(), TerraformCloudWorkspaceDetails: &waypoint_models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: plan.TerraformCloudWorkspace.Name.ValueString(), ProjectID: plan.TerraformCloudWorkspace.TerraformProjectID.ValueString(), @@ -315,6 +300,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques plan.Name = types.StringValue(appTemplate.Name) plan.OrgID = types.StringValue(orgID) plan.Summary = types.StringValue(appTemplate.Summary) + plan.TerraformNoCodeModuleSource = types.StringValue(appTemplate.TerraformNocodeModule.Source) if appTemplate.TerraformCloudWorkspaceDetails != nil { tfcWorkspace := &tfcWorkspace{ @@ -324,14 +310,6 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques plan.TerraformCloudWorkspace = tfcWorkspace } - if appTemplate.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(appTemplate.TerraformNocodeModule.Source), - Version: types.StringValue(appTemplate.TerraformNocodeModule.Version), - } - plan.TerraformNoCodeModule = tfcNoCode - } - labels, diags := types.ListValueFrom(ctx, types.StringType, appTemplate.Labels) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -437,6 +415,7 @@ func (r *TemplateResource) Read(ctx context.Context, req resource.ReadRequest, r data.OrgID = types.StringValue(client.Config.OrganizationID) data.ProjectID = types.StringValue(client.Config.ProjectID) data.Summary = types.StringValue(appTemplate.Summary) + data.TerraformNoCodeModuleSource = types.StringValue(appTemplate.TerraformNocodeModule.Source) if appTemplate.TerraformCloudWorkspaceDetails != nil { tfcWorkspace := &tfcWorkspace{ @@ -446,14 +425,6 @@ func (r *TemplateResource) Read(ctx context.Context, req resource.ReadRequest, r data.TerraformCloudWorkspace = tfcWorkspace } - if appTemplate.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(appTemplate.TerraformNocodeModule.Source), - Version: types.StringValue(appTemplate.TerraformNocodeModule.Version), - } - data.TerraformNoCodeModule = tfcNoCode - } - data.TerraformVariableOptions, err = readVarOpts(ctx, appTemplate.VariableOptions, &resp.Diagnostics) if err != nil { tflog.Error(ctx, err.Error()) @@ -555,10 +526,7 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques Labels: strLabels, Description: plan.Description.ValueString(), ReadmeMarkdownTemplate: readmeBytes, - TerraformNocodeModule: &waypoint_models.HashicorpCloudWaypointTerraformNocodeModule{ - Source: plan.TerraformNoCodeModule.Source.ValueString(), - Version: plan.TerraformNoCodeModule.Version.ValueString(), - }, + ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(), TerraformCloudWorkspaceDetails: &waypoint_models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: plan.TerraformCloudWorkspace.Name.ValueString(), ProjectID: plan.TerraformCloudWorkspace.TerraformProjectID.ValueString(), @@ -592,6 +560,7 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques plan.Name = types.StringValue(appTemplate.Name) plan.OrgID = types.StringValue(orgID) plan.Summary = types.StringValue(appTemplate.Summary) + plan.TerraformNoCodeModuleSource = types.StringValue(appTemplate.TerraformNocodeModule.Source) labels, diags := types.ListValueFrom(ctx, types.StringType, appTemplate.Labels) resp.Diagnostics.Append(diags...) @@ -608,14 +577,6 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques plan.TerraformCloudWorkspace = tfcWorkspace } - if appTemplate.TerraformNocodeModule != nil { - tfcNoCode := &tfcNoCodeModule{ - Source: types.StringValue(appTemplate.TerraformNocodeModule.Source), - Version: types.StringValue(appTemplate.TerraformNocodeModule.Version), - } - plan.TerraformNoCodeModule = tfcNoCode - } - plan.Description = types.StringValue(appTemplate.Description) if appTemplate.Description == "" { plan.Description = types.StringNull() diff --git a/internal/provider/waypoint/resource_waypoint_template_test.go b/internal/provider/waypoint/resource_waypoint_template_test.go index 2e962ee31..1f6cd2ff7 100644 --- a/internal/provider/waypoint/resource_waypoint_template_test.go +++ b/internal/provider/waypoint/resource_waypoint_template_test.go @@ -157,10 +157,7 @@ resource "hcp_waypoint_template" "test" { name = "%s" summary = "some summary for fun" readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-template-starter/null" - version = "0.0.2" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o" @@ -175,10 +172,7 @@ resource "hcp_waypoint_template" "var_opts_test" { name = "%s" summary = "A template with a variable with options." readme_markdown_template = base64encode("# Some Readme") - terraform_no_code_module = { - source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" - version = "0.0.1" - } + terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null" terraform_cloud_workspace_details = { name = "Default Project" terraform_project_id = "prj-gfVyPJ2q2Aurn25o"