From 89f843530c27b17323e6474322c64de4bbff2cf4 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Mon, 18 Aug 2025 09:18:29 +0000 Subject: [PATCH 1/3] feat: add `use_classic_parameter_flow` to `coderd_template` resource --- internal/provider/template_resource.go | 43 ++++++++++++++++++--- internal/provider/template_resource_test.go | 3 ++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/internal/provider/template_resource.go b/internal/provider/template_resource.go index b95d036..d55ea5d 100644 --- a/internal/provider/template_resource.go +++ b/internal/provider/template_resource.go @@ -24,6 +24,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -72,6 +73,7 @@ type TemplateResourceModel struct { RequireActiveVersion types.Bool `tfsdk:"require_active_version"` DeprecationMessage types.String `tfsdk:"deprecation_message"` MaxPortShareLevel types.String `tfsdk:"max_port_share_level"` + UseClassicParameterFlow types.Bool `tfsdk:"use_classic_parameter_flow"` // If null, we are not managing ACL via Terraform (such as for AGPL). ACL types.Object `tfsdk:"acl"` @@ -97,7 +99,8 @@ func (m *TemplateResourceModel) EqualTemplateMetadata(other *TemplateResourceMod m.TimeTilDormantAutoDeleteMillis.Equal(other.TimeTilDormantAutoDeleteMillis) && m.RequireActiveVersion.Equal(other.RequireActiveVersion) && m.DeprecationMessage.Equal(other.DeprecationMessage) && - m.MaxPortShareLevel.Equal(other.MaxPortShareLevel) + m.MaxPortShareLevel.Equal(other.MaxPortShareLevel) && + m.UseClassicParameterFlow.Equal(other.UseClassicParameterFlow) } func (m *TemplateResourceModel) CheckEntitlements(ctx context.Context, features map[codersdk.FeatureName]codersdk.Feature) (diags diag.Diagnostics) { @@ -385,6 +388,9 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques Validators: []validator.String{ stringvalidator.OneOfCaseInsensitive(string(codersdk.WorkspaceAgentPortShareLevelAuthenticated), string(codersdk.WorkspaceAgentPortShareLevelOwner), string(codersdk.WorkspaceAgentPortShareLevelPublic)), }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, }, "deprecation_message": schema.StringAttribute{ MarkdownDescription: "If set, the template will be marked as deprecated with the provided message and users will be blocked from creating new workspaces from it. Does nothing if set when the resource is created.", @@ -392,6 +398,14 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques Computed: true, Default: stringdefault.StaticString(""), }, + "use_classic_parameter_flow": schema.BoolAttribute{ + MarkdownDescription: "If true, the classic parameter flow will be used when creating workspaces from this template. This only affects deployments with the experiment \"dynamic-parameters\" enabled. Defaults to false.", + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, "acl": schema.SingleNestedAttribute{ MarkdownDescription: "(Enterprise) Access control list for the template. If null, ACL policies will not be added, removed, or read by Terraform.", Optional: true, @@ -588,6 +602,25 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques data.MaxPortShareLevel = types.StringValue(string(mpslResp.MaxPortShareLevel)) } + // TODO: Remove this update call (and the attribute) once the provider + // requires a Coder version where this flag has been removed. + if data.UseClassicParameterFlow.IsUnknown() { + data.UseClassicParameterFlow = types.BoolValue(templateResp.UseClassicParameterFlow) + } else if data.UseClassicParameterFlow.ValueBool() == templateResp.UseClassicParameterFlow { + tflog.Info(ctx, "use classic parameter flow set to default, not updating") + } else { + ucpfReq := data.toUpdateRequest(ctx, &resp.Diagnostics) + if resp.Diagnostics.HasError() { + return + } + ucpfResp, err := client.UpdateTemplateMeta(ctx, data.ID.ValueUUID(), *ucpfReq) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to set use classic parameter flow via update: %s", err)) + return + } + data.UseClassicParameterFlow = types.BoolValue(ucpfResp.UseClassicParameterFlow) + } + resp.Diagnostics.Append(data.Versions.setPrivateState(ctx, resp.Private)...) if resp.Diagnostics.HasError() { return @@ -627,6 +660,7 @@ func (r *TemplateResource) Read(ctx context.Context, req resource.ReadRequest, r return } data.MaxPortShareLevel = types.StringValue(string(template.MaxPortShareLevel)) + data.UseClassicParameterFlow = types.BoolValue(template.UseClassicParameterFlow) if !data.ACL.IsNull() { tflog.Info(ctx, "reading template ACL") @@ -701,11 +735,6 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques client := r.data.Client - // TODO(ethanndickson): Remove this once the provider requires a Coder - // deployment running `v2.15.0` or later. - if newState.MaxPortShareLevel.IsUnknown() { - newState.MaxPortShareLevel = curState.MaxPortShareLevel - } templateMetadataChanged := !newState.EqualTemplateMetadata(&curState) // This is required, as the API will reject no-diff updates. if templateMetadataChanged { @@ -1290,6 +1319,7 @@ func (r *TemplateResourceModel) toUpdateRequest(ctx context.Context, diag *diag. RequireActiveVersion: r.RequireActiveVersion.ValueBool(), DeprecationMessage: r.DeprecationMessage.ValueStringPointer(), MaxPortShareLevel: ptr.Ref(codersdk.WorkspaceAgentPortShareLevel(r.MaxPortShareLevel.ValueString())), + UseClassicParameterFlow: ptr.Ref(r.UseClassicParameterFlow.ValueBool()), // If we're managing ACL, we want to delete the everyone group DisableEveryoneGroupAccess: !r.ACL.IsNull(), } @@ -1334,6 +1364,7 @@ func (r *TemplateResourceModel) toCreateRequest(ctx context.Context, resp *resou TimeTilDormantMillis: r.TimeTilDormantMillis.ValueInt64Pointer(), TimeTilDormantAutoDeleteMillis: r.TimeTilDormantAutoDeleteMillis.ValueInt64Pointer(), RequireActiveVersion: r.RequireActiveVersion.ValueBool(), + UseClassicParameterFlow: r.UseClassicParameterFlow.ValueBoolPointer(), DisableEveryoneGroupAccess: !r.ACL.IsNull(), } } diff --git a/internal/provider/template_resource_test.go b/internal/provider/template_resource_test.go index f56ff3b..b21e1c0 100644 --- a/internal/provider/template_resource_test.go +++ b/internal/provider/template_resource_test.go @@ -116,6 +116,7 @@ func TestAccTemplateResource(t *testing.T) { resource.TestCheckResourceAttr("coderd_template.test", "time_til_dormant_autodelete_ms", "0"), resource.TestCheckResourceAttr("coderd_template.test", "require_active_version", "false"), resource.TestCheckResourceAttr("coderd_template.test", "max_port_share_level", "public"), + resource.TestCheckResourceAttr("coderd_template.test", "use_classic_parameter_flow", "false"), resource.TestMatchTypeSetElemNestedAttrs("coderd_template.test", "versions.*", map[string]*regexp.Regexp{ "name": regexp.MustCompile(".+"), "id": regexp.MustCompile(".+"), @@ -991,6 +992,7 @@ type testAccTemplateResourceConfig struct { RequireActiveVersion *bool DeprecationMessage *string MaxPortShareLevel *string + UseClassicParameterFlow *bool Versions []testAccTemplateVersionConfig ACL testAccTemplateACLConfig @@ -1098,6 +1100,7 @@ resource "coderd_template" "test" { require_active_version = {{orNull .RequireActiveVersion}} deprecation_message = {{orNull .DeprecationMessage}} max_port_share_level = {{orNull .MaxPortShareLevel}} + use_classic_parameter_flow = {{orNull .UseClassicParameterFlow}} acl = ` + c.ACL.String(t) + ` From 732ec3d7d378f17a01029f68cfbdd868bbc73ba3 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Mon, 18 Aug 2025 09:20:07 +0000 Subject: [PATCH 2/3] wip --- docs/resources/template.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/resources/template.md b/docs/resources/template.md index 5e5d77a..1e05504 100644 --- a/docs/resources/template.md +++ b/docs/resources/template.md @@ -83,6 +83,7 @@ resource "coderd_template" "ubuntu-main" { - `require_active_version` (Boolean) (Enterprise) Whether workspaces must be created from the active version of this template. Defaults to false. - `time_til_dormant_autodelete_ms` (Number) (Enterprise) The max lifetime before Coder permanently deletes dormant workspaces created from this template. - `time_til_dormant_ms` (Number) (Enterprise) The max lifetime before Coder locks inactive workspaces created from this template, in milliseconds. +- `use_classic_parameter_flow` (Boolean) If true, the classic parameter flow will be used when creating workspaces from this template. This only affects deployments with the experiment "dynamic-parameters" enabled. Defaults to false. ### Read-Only From ec55fe1a1dc99bfab5e55edf60ecafee90c52e0b Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Tue, 19 Aug 2025 00:25:29 +0000 Subject: [PATCH 3/3] review --- docs/resources/template.md | 2 +- internal/provider/template_resource.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/template.md b/docs/resources/template.md index 1e05504..a7a95f8 100644 --- a/docs/resources/template.md +++ b/docs/resources/template.md @@ -83,7 +83,7 @@ resource "coderd_template" "ubuntu-main" { - `require_active_version` (Boolean) (Enterprise) Whether workspaces must be created from the active version of this template. Defaults to false. - `time_til_dormant_autodelete_ms` (Number) (Enterprise) The max lifetime before Coder permanently deletes dormant workspaces created from this template. - `time_til_dormant_ms` (Number) (Enterprise) The max lifetime before Coder locks inactive workspaces created from this template, in milliseconds. -- `use_classic_parameter_flow` (Boolean) If true, the classic parameter flow will be used when creating workspaces from this template. This only affects deployments with the experiment "dynamic-parameters" enabled. Defaults to false. +- `use_classic_parameter_flow` (Boolean) If true, the classic parameter flow will be used when creating workspaces from this template. Defaults to false. ### Read-Only diff --git a/internal/provider/template_resource.go b/internal/provider/template_resource.go index d55ea5d..a981bd0 100644 --- a/internal/provider/template_resource.go +++ b/internal/provider/template_resource.go @@ -399,7 +399,7 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques Default: stringdefault.StaticString(""), }, "use_classic_parameter_flow": schema.BoolAttribute{ - MarkdownDescription: "If true, the classic parameter flow will be used when creating workspaces from this template. This only affects deployments with the experiment \"dynamic-parameters\" enabled. Defaults to false.", + MarkdownDescription: "If true, the classic parameter flow will be used when creating workspaces from this template. Defaults to false.", Optional: true, Computed: true, PlanModifiers: []planmodifier.Bool{ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy