Skip to content

Commit

Permalink
Added useModuleReadme field (#1099)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HenryEstberg authored Sep 27, 2024
1 parent a079d9f commit 4ed1822
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/1099.txt
Original file line number Diff line number Diff line change
@@ -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.
```
1 change: 1 addition & 0 deletions docs/resources/waypoint_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions internal/provider/waypoint/resource_waypoint_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4ed1822

Please sign in to comment.