Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 33a851b

Browse files
committed
Validate that the template exists before proceeding
1 parent e709e02 commit 33a851b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

octopusdeploy_framework/resource_tenant_project_variable.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ func (t *tenantProjectVariableResource) Read(ctx context.Context, req resource.R
125125
return
126126
}
127127

128+
if !checkIfTemplateExists(tenantVariables, state) {
129+
// The template no longer exists, so the variable can no longer exist either
130+
return
131+
}
132+
128133
isSensitive, err := checkIfVariableIsSensitive(tenantVariables, state)
129134
if err != nil {
130135
resp.Diagnostics.AddError("Error checking if variable is sensitive", err.Error())
@@ -251,6 +256,17 @@ func (t *tenantProjectVariableResource) ImportState(ctx context.Context, req res
251256
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("template_id"), idParts[3])...)
252257
}
253258

259+
func checkIfTemplateExists(tenantVariables *variables.TenantVariables, plan tenantProjectVariableResourceModel) bool {
260+
if projectVariable, ok := tenantVariables.ProjectVariables[plan.ProjectID.ValueString()]; ok {
261+
for _, template := range projectVariable.Templates {
262+
if template.GetID() == plan.TemplateID.ValueString() {
263+
return true
264+
}
265+
}
266+
}
267+
return false
268+
}
269+
254270
func checkIfVariableIsSensitive(tenantVariables *variables.TenantVariables, plan tenantProjectVariableResourceModel) (bool, error) {
255271
if projectVariable, ok := tenantVariables.ProjectVariables[plan.ProjectID.ValueString()]; ok {
256272
for _, template := range projectVariable.Templates {

0 commit comments

Comments
 (0)