@@ -512,21 +512,9 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
512512 }
513513}
514514
515- func (r * clusterResource ) ValidateConfig (ctx context.Context , req resource.ValidateConfigRequest , resp * resource.ValidateConfigResponse ) {
516- var model Model
517- diags := req .Config .Get (ctx , & model )
518- resp .Diagnostics .Append (diags ... )
519- if resp .Diagnostics .HasError () {
520- return
521- }
522-
523- diags = checkAllowPrivilegedContainers (model .AllowPrivilegedContainers , model .KubernetesVersion )
524- resp .Diagnostics .Append (diags ... )
525- if resp .Diagnostics .HasError () {
526- return
527- }
528- }
529-
515+ // needs to be executed inside the Create and Update methods
516+ // since ValidateConfig runs before variables are rendered to their value,
517+ // which causes errors like this: https://github.com/stackitcloud/terraform-provider-stackit/issues/201
530518func checkAllowPrivilegedContainers (allowPrivilegeContainers types.Bool , kubernetesVersion types.String ) diag.Diagnostics {
531519 var diags diag.Diagnostics
532520
@@ -556,6 +544,13 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
556544 if resp .Diagnostics .HasError () {
557545 return
558546 }
547+
548+ diags = checkAllowPrivilegedContainers (model .AllowPrivilegedContainers , model .KubernetesVersion )
549+ resp .Diagnostics .Append (diags ... )
550+ if resp .Diagnostics .HasError () {
551+ return
552+ }
553+
559554 projectId := model .ProjectId .ValueString ()
560555 clusterName := model .Name .ValueString ()
561556 ctx = tflog .SetField (ctx , "project_id" , projectId )
@@ -1393,6 +1388,13 @@ func (r *clusterResource) Update(ctx context.Context, req resource.UpdateRequest
13931388 if resp .Diagnostics .HasError () {
13941389 return
13951390 }
1391+
1392+ diags = checkAllowPrivilegedContainers (model .AllowPrivilegedContainers , model .KubernetesVersion )
1393+ resp .Diagnostics .Append (diags ... )
1394+ if resp .Diagnostics .HasError () {
1395+ return
1396+ }
1397+
13961398 projectId := model .ProjectId .ValueString ()
13971399 clName := model .Name .ValueString ()
13981400 ctx = tflog .SetField (ctx , "project_id" , projectId )
0 commit comments