From 4ed182205509530689b1540eca84c923fcff0edf Mon Sep 17 00:00:00 2001 From: HenryEstberg <11286201+HenryEstberg@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:38:32 -0700 Subject: [PATCH] Added useModuleReadme field (#1099) The use_module_readme attribute allows users to elect to use the readme of their Waypoint template's associated Terraform module in place of providing a readme for that template themselves. --- .changelog/1099.txt | 3 +++ docs/resources/waypoint_template.md | 1 + .../waypoint/resource_waypoint_template.go | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 .changelog/1099.txt diff --git a/.changelog/1099.txt b/.changelog/1099.txt new file mode 100644 index 000000000..e625efe51 --- /dev/null +++ b/.changelog/1099.txt @@ -0,0 +1,3 @@ +```release-note:feature +Waypoint: New template resource attribute `use_module_readme` allows users to use the associated Terraform module readme in place of providing a seperate readme for the template. +``` \ No newline at end of file diff --git a/docs/resources/waypoint_template.md b/docs/resources/waypoint_template.md index 0f55dfb6f..06fc3341b 100644 --- a/docs/resources/waypoint_template.md +++ b/docs/resources/waypoint_template.md @@ -30,6 +30,7 @@ Waypoint Template resource - `terraform_agent_pool_id` (String) The ID of the agent pool to use for Terraform operations, for workspaces created for applications using this template. Required if terraform_execution_mode is set to 'agent'. - `terraform_cloud_workspace_details` (Attributes, Deprecated) Terraform Cloud Workspace details (see [below for nested schema](#nestedatt--terraform_cloud_workspace_details)) - `terraform_execution_mode` (String) The execution mode of the HCP Terraform workspaces created for applications using this template. +- `use_module_readme` (Boolean) If true, will auto-import the readme form the Terraform odule used. If this is set to true, users should not also set `readme_markdown_template`. - `variable_options` (Attributes Set) List of variable options for the template. (see [below for nested schema](#nestedatt--variable_options)) ### Read-Only diff --git a/internal/provider/waypoint/resource_waypoint_template.go b/internal/provider/waypoint/resource_waypoint_template.go index 082bc7df8..e9d7de9b3 100644 --- a/internal/provider/waypoint/resource_waypoint_template.go +++ b/internal/provider/waypoint/resource_waypoint_template.go @@ -49,6 +49,7 @@ type TemplateResourceModel struct { Labels types.List `tfsdk:"labels"` Description types.String `tfsdk:"description"` ReadmeMarkdownTemplate types.String `tfsdk:"readme_markdown_template"` + UseModuleReadme types.Bool `tfsdk:"use_module_readme"` TerraformProjectID types.String `tfsdk:"terraform_project_id"` TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"` @@ -124,8 +125,13 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques }, "readme_markdown_template": schema.StringAttribute{ Optional: true, + Computed: true, Description: "Instructions for using the template (markdown format supported).", }, + "use_module_readme": schema.BoolAttribute{ + Optional: true, + Description: "If true, will auto-import the readme form the Terraform odule used. If this is set to true, users should not also set `readme_markdown_template`.", + }, "labels": schema.ListAttribute{ // Computed: true, Optional: true, @@ -302,6 +308,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques TfExecutionMode: plan.TerraformExecutionMode.ValueString(), TfAgentPoolID: plan.TerraformAgentPoolID.ValueString(), }, + UseModuleReadme: plan.UseModuleReadme.ValueBool(), } // Decode the base64 encoded readme markdown template to see if it is encoded @@ -335,6 +342,11 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques return } + // If plan.UseModuleReadme is not set, set it to false + if plan.UseModuleReadme.IsUnknown() { + plan.UseModuleReadme = types.BoolValue(false) + } + plan.ID = types.StringValue(appTemplate.ID) plan.ProjectID = types.StringValue(projectID) plan.Name = types.StringValue(appTemplate.Name) @@ -578,6 +590,7 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques TfExecutionMode: plan.TerraformExecutionMode.ValueString(), TfAgentPoolID: plan.TerraformAgentPoolID.ValueString(), }, + UseModuleReadme: plan.UseModuleReadme.ValueBool(), } // Decode the base64 encoded readme markdown template to see if it is encoded @@ -612,6 +625,11 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques return } + // If plan.UseModuleReadme is not set, set it to false + if plan.UseModuleReadme.IsUnknown() { + plan.UseModuleReadme = types.BoolValue(false) + } + plan.ID = types.StringValue(appTemplate.ID) plan.ProjectID = types.StringValue(projectID) plan.Name = types.StringValue(appTemplate.Name)