Skip to content

feat: add use_classic_parameter_flow to coderd_template resource #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. Defaults to false.

### Read-Only

Expand Down
43 changes: 37 additions & 6 deletions internal/provider/template_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand All @@ -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) {
Expand Down Expand Up @@ -385,13 +388,24 @@ 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.",
Optional: true,
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. 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,
Expand Down Expand Up @@ -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.
Comment on lines +605 to +606
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coder 2.24 does not include the bool on CreateTemplateRequest, only on UpdateTemplateMeta. 2.25 does include it on CreateTemplateRequest, however.

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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Comment on lines -704 to -708
Copy link
Member Author

@ethanndickson ethanndickson Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this because I realised I could use planmodifier UseStateForUnknown for it.

templateMetadataChanged := !newState.EqualTemplateMetadata(&curState)
// This is required, as the API will reject no-diff updates.
if templateMetadataChanged {
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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(),
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/template_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(".+"),
Expand Down Expand Up @@ -991,6 +992,7 @@ type testAccTemplateResourceConfig struct {
RequireActiveVersion *bool
DeprecationMessage *string
MaxPortShareLevel *string
UseClassicParameterFlow *bool

Versions []testAccTemplateVersionConfig
ACL testAccTemplateACLConfig
Expand Down Expand Up @@ -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) + `

Expand Down
Loading
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