Skip to content

Intermittent error for 'stackit_server.with_key_pair' #1223

@fratze

Description

@fratze

Description

We are intermittently encountering the following Terraform error when deploying multiple VMs (e.g., 6) using the stackit_server.with_key_pair resource:

│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to
│ module.dt_active_gate["0"].stackit_server.with_key_pair, provider
│ "provider[\"registry.terraform.io/stackitcloud/stackit\"]" produced an
│ unexpected new value: .keypair_name: was
│ cty.StringVal("develop1-dt-active-gate-0-key-pair"), but now null.
│
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

More information can be found in the STACKIT Help Center ticket SSD-16229

Steps to reproduce

As the issue occurs only from time to time it is difficult to reproduce. Our Terraform configuration & setup can be found in the Help Center ticket SSD-16229.

Actual behavior

When running terraform apply the stackit_server.with_key_pair resources are created and usable, i.e. we can login to the VMs with the provisioned SSH keys.

However, due to the error the Terraform state is "broken/incomplete" so that Terraform re-creates the affected machines on the next apply.

Expected behavior

The expectation is that the Terraform state reflects the correct instantiation of the created servers and does not error out.

Environment

  • OS: Linux Ubuntu 24.04
  • Terraform version (see terraform --version): v1.14.0
  • Version of the STACKIT Terraform provider: v0.80.0

Additional information

When looking at the stackitcloud/terraform-provider-stackit/main/stackit/internal/services/iaas/server/resource.go at Line 1011 where the error seems to occurr,

	model.KeypairName = types.StringPointerValue(serverResp.KeypairName)

it can be noticed, that a couple of lines above, e.g. Lines 1005-1007

	if serverResp.UserData != nil && len(*serverResp.UserData) > 0 {
		model.UserData = types.StringValue(string(*serverResp.UserData))
	}

a condition exists that catches nil/null responses for other model.* fields.

Thus, we applied the same mechansim to the model.KeypairName parameter

	if serverResp.KeypairName != nil && *serverResp.KeypairName != "" {
		model.KeypairName = types.StringPointerValue(serverResp.KeypairName)
	}

and tested this fix successfully with our Terraform configurations again.
I.e. this seems to have fixed the error.

However, since the error occurs intermittently, longer-term validation is still pending.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions