diff --git a/internal/provider/waypoint/data_source_waypoint_add_on.go b/internal/provider/waypoint/data_source_waypoint_add_on.go index 1a6aa7279..696e1ad6b 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"` } @@ -121,19 +121,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, @@ -243,6 +233,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...) @@ -254,18 +245,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 6b7ad5d5b..99d7f1581 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 != "" { @@ -557,6 +526,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 @@ -576,18 +546,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 @@ -719,6 +677,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 @@ -738,18 +697,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 63cd993dd..1e751223a 100644 --- a/internal/provider/waypoint/resource_waypoint_add_on_definition.go +++ b/internal/provider/waypoint/resource_waypoint_add_on_definition.go @@ -48,7 +48,7 @@ type AddOnDefinitionResourceModel struct { ReadmeMarkdownTemplate types.String `tfsdk:"readme_markdown_template"` TerraformCloudWorkspace types.Object `tfsdk:"terraform_cloud_workspace_details"` - TerraformNoCodeModule *tfcNoCodeModule `tfsdk:"terraform_no_code_module"` + TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"` TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"` } @@ -125,20 +125,13 @@ 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 , expected to be in one of the following formats:" + - " \"app.terraform.io/hcp_waypoint_example/ecs-advanced-microservice/aws\" or " + - "\"private/hcp_waypoint_example/ecs-advanced-microservice/aws\"", - }, - "version": &schema.StringAttribute{ - Required: true, - Description: "Terraform Cloud no-code Module Version", - }, + Description: "Terraform Cloud no-code Module Source, expected to be in one of the following formats:" + + " \"app.terraform.io/hcp_waypoint_example/ecs-advanced-microservice/aws\" or " + + "\"private/hcp_waypoint_example/ecs-advanced-microservice/aws\"", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, "variable_options": schema.SetNestedAttribute{ @@ -253,15 +246,11 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat } modelBody := &waypointModels.HashicorpCloudWaypointWaypointServiceCreateAddOnDefinitionBody{ - Name: plan.Name.ValueString(), - Summary: plan.Summary.ValueString(), - Description: plan.Description.ValueString(), - Labels: stringLabels, - TerraformNocodeModule: &waypointModels.HashicorpCloudWaypointTerraformNocodeModule{ - // verify these exist in the file - Source: plan.TerraformNoCodeModule.Source.ValueString(), - Version: plan.TerraformNoCodeModule.Version.ValueString(), - }, + Name: plan.Name.ValueString(), + Summary: plan.Summary.ValueString(), + Description: plan.Description.ValueString(), + Labels: stringLabels, + ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(), VariableOptions: varOpts, } @@ -314,6 +303,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 @@ -345,14 +335,6 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat } } - 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()) @@ -406,6 +388,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 @@ -437,14 +420,6 @@ func (r *AddOnDefinitionResource) Read(ctx context.Context, req resource.ReadReq } } - 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()) @@ -515,15 +490,11 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat // TODO: add support for Tags modelBody := &waypointModels.HashicorpCloudWaypointWaypointServiceUpdateAddOnDefinitionBody{ - Name: plan.Name.ValueString(), - Summary: plan.Summary.ValueString(), - Description: plan.Description.ValueString(), - Labels: stringLabels, - TerraformNocodeModule: &waypointModels.HashicorpCloudWaypointTerraformNocodeModule{ - // verify these exist in the file - Source: plan.TerraformNoCodeModule.Source.ValueString(), - Version: plan.TerraformNoCodeModule.Version.ValueString(), - }, + Name: plan.Name.ValueString(), + Summary: plan.Summary.ValueString(), + Description: plan.Description.ValueString(), + Labels: stringLabels, + ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(), VariableOptions: varOpts, } @@ -577,6 +548,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 @@ -608,14 +580,6 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat } } - 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 cd4bf8d62..364b766e7 100644 --- a/internal/provider/waypoint/resource_waypoint_template.go +++ b/internal/provider/waypoint/resource_waypoint_template.go @@ -50,9 +50,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 { @@ -151,18 +151,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", - }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, "variable_options": schema.SetNestedAttribute{ @@ -274,14 +267,11 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceCreateApplicationTemplateBody{ ApplicationTemplate: &waypoint_models.HashicorpCloudWaypointApplicationTemplate{ - Name: plan.Name.ValueString(), - Summary: plan.Summary.ValueString(), - Labels: strLabels, - Description: plan.Description.ValueString(), - TerraformNocodeModule: &waypoint_models.HashicorpCloudWaypointTerraformNocodeModule{ - Source: plan.TerraformNoCodeModule.Source.ValueString(), - Version: plan.TerraformNoCodeModule.Version.ValueString(), - }, + Name: plan.Name.ValueString(), + Summary: plan.Summary.ValueString(), + Labels: strLabels, + Description: plan.Description.ValueString(), + ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(), TerraformCloudWorkspaceDetails: &waypoint_models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: plan.TerraformCloudWorkspace.Name.ValueString(), ProjectID: plan.TerraformCloudWorkspace.TerraformProjectID.ValueString(), @@ -326,6 +316,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{ @@ -335,14 +326,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() { @@ -448,6 +431,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{ @@ -457,14 +441,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()) @@ -552,14 +528,11 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceUpdateApplicationTemplateBody{ ApplicationTemplate: &waypoint_models.HashicorpCloudWaypointApplicationTemplate{ - Name: plan.Name.ValueString(), - Summary: plan.Summary.ValueString(), - Labels: strLabels, - Description: plan.Description.ValueString(), - TerraformNocodeModule: &waypoint_models.HashicorpCloudWaypointTerraformNocodeModule{ - Source: plan.TerraformNoCodeModule.Source.ValueString(), - Version: plan.TerraformNoCodeModule.Version.ValueString(), - }, + Name: plan.Name.ValueString(), + Summary: plan.Summary.ValueString(), + Labels: strLabels, + Description: plan.Description.ValueString(), + ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(), TerraformCloudWorkspaceDetails: &waypoint_models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: plan.TerraformCloudWorkspace.Name.ValueString(), ProjectID: plan.TerraformCloudWorkspace.TerraformProjectID.ValueString(), @@ -605,6 +578,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...) @@ -621,14 +595,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"