digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
503 stars 276 forks source link

digitalocean_ssh_key race condition (roduced an unexpected new value: Root object was present, but now absent) #1163

Closed speedythesnail closed 4 weeks ago

speedythesnail commented 4 months ago

Bug Report


Describe the bug

When creating SSH keys, it appears there is a race condition where the SSH key is created but Terraform provides the below error message:

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to module.ssh.digitalocean_ssh_key.personal_ssh_key,
│ provider
│ "module.ssh.provider[\"registry.terraform.io/digitalocean/digitalocean\"]"
│ produced an unexpected new value: Root object was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

When I set the TF_LOG level to trace, I see that the SSH key is in fact created, and immediately after, the provider performs a GET request to get the key that was created, resulting in a 404 error. I manually performed a curl and see the key exists and it shows up in the Digital Ocean control panel.

I suspect there is a race condition, where the key was in fact created, but we are trying to retrieve information by performing the GET request too soon. See the below excerpt from the Terraform log:

2024-05-22T09:15:03.692-0400 [TRACE] checkPlannedChange: Verifying that actual change (action Create) matches planned change (action Create)
module.ssh.digitalocean_ssh_key.personal_ssh_key: Creating...
2024-05-22T09:15:03.692-0400 [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/digitalocean/digitalocean" is in the global cache
2024-05-22T09:15:03.692-0400 [INFO]  Starting apply for module.ssh.digitalocean_ssh_key.personal_ssh_key
2024-05-22T09:15:03.692-0400 [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/digitalocean/digitalocean" is in the global cache
2024-05-22T09:15:03.692-0400 [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/digitalocean/digitalocean" is in the global cache
2024-05-22T09:15:03.692-0400 [DEBUG] module.ssh.digitalocean_ssh_key.personal_ssh_key: applying the planned Create change
2024-05-22T09:15:03.692-0400 [TRACE] GRPCProvider: ApplyResourceChange
2024-05-22T09:15:03.692-0400 [TRACE] GRPCProvider: GetProviderSchema
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Called downstream: @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:218 @module=sdk.helper_schema tf_provider_addr=provider tf_req_id=636a3756-0aad-10b3-7456-4ede6a1f1d04 tf_rpc=PrepareProviderConfig timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Received request: @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:805 tf_proto_version=5.3 tf_provider_addr=provider tf_req_id=2bd7df7d-6233-0893-1345-eba3cef4a701 tf_resource_type=digitalocean_ssh_key @module=sdk.proto tf_rpc=ApplyResourceChange timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Sending request downstream: @module=sdk.proto tf_req_id=2bd7df7d-6233-0893-1345-eba3cef4a701 tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tf5serverlogging/downstream_request.go:17 tf_proto_version=5.3 tf_provider_addr=provider tf_resource_type=digitalocean_ssh_key timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Received downstream response: diagnostic_warning_count=0 tf_provider_addr=provider tf_req_duration_ms=1 tf_req_id=636a3756-0aad-10b3-7456-4ede6a1f1d04 tf_rpc=PrepareProviderConfig @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tf5serverlogging/downstream_request.go:37 @module=sdk.proto diagnostic_error_count=0 tf_proto_version=5.3 timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Served request: @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:539 @module=sdk.proto tf_proto_version=5.3 tf_provider_addr=provider tf_req_id=636a3756-0aad-10b3-7456-4ede6a1f1d04 tf_rpc=PrepareProviderConfig timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Calling downstream: tf_req_id=2bd7df7d-6233-0893-1345-eba3cef4a701 tf_provider_addr=provider tf_resource_type=digitalocean_ssh_key tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:836 @module=sdk.helper_schema timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [DEBUG] SSH Key create configuration: &godo.KeyCreateRequest{Name:"some.email@email.com", PublicKey:"REDACTED"}: timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [WARN]  ValidateProviderConfig from "module.domain.provider[\"registry.terraform.io/digitalocean/digitalocean\"]" changed the config value, but that value is unused
2024-05-22T09:15:03.693-0400 [TRACE] GRPCProvider: ConfigureProvider
2024-05-22T09:15:03.693-0400 [TRACE] GRPCProvider: GetProviderSchema
2024-05-22T09:15:03.693-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [DEBUG] DigitalOcean API Request Details:
---[ REQUEST ]---------------------------------------
POST /v2/account/keys HTTP/1.1
Host: api.digitalocean.com
User-Agent: Terraform/1.8.3 godo/1.113.0
Content-Length: 155
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip

{
 "name": "some.email@email.com",
 "public_key": "REDACTED"
}

-----------------------------------------------------: timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [DEBUG] POST https://api.digitalocean.com/v2/account/keys: timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Received request: tf_proto_version=5.3 tf_req_id=eda3429c-2be1-4045-dde1-c78a585b28c9 tf_rpc=Configure @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:547 @module=sdk.proto tf_provider_addr=provider timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Sending request downstream: tf_proto_version=5.3 tf_rpc=Configure @module=sdk.proto tf_req_id=eda3429c-2be1-4045-dde1-c78a585b28c9 @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tf5serverlogging/downstream_request.go:17 tf_provider_addr=provider timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Calling downstream: tf_provider_addr=provider tf_req_id=eda3429c-2be1-4045-dde1-c78a585b28c9 tf_rpc=Configure @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:556 @module=sdk.helper_schema timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [INFO] DigitalOcean Client configured for URL: https://api.digitalocean.com: timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Called downstream: tf_req_id=eda3429c-2be1-4045-dde1-c78a585b28c9 tf_rpc=Configure @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:558 @module=sdk.helper_schema tf_provider_addr=provider timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Received downstream response: tf_proto_version=5.3 tf_req_duration_ms=0 tf_req_id=eda3429c-2be1-4045-dde1-c78a585b28c9 @module=sdk.proto diagnostic_error_count=0 @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tf5serverlogging/downstream_request.go:37 diagnostic_warning_count=0 tf_provider_addr=provider tf_rpc=Configure timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.693-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Served request: @module=sdk.proto tf_provider_addr=provider tf_req_id=eda3429c-2be1-4045-dde1-c78a585b28c9 tf_rpc=Configure tf_proto_version=5.3 @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:567 timestamp=2024-05-22T09:15:03.693-0400
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.provider[\"registry.terraform.io/digitalocean/digitalocean\"]": visit complete
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.digitalocean_domain.personal_company_domain_root (expand)": starting visit (*terraform.nodeExpandApplyableResource)
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.digitalocean_domain.personal_company_domain_root (expand)": does not belong to any module instance
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.digitalocean_domain.personal_company_domain_root (expand)": visit complete
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id (expand)": starting visit (*terraform.nodeExpandOutput)
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id (expand)": does not belong to any module instance
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id (expand)": expanding dynamic subgraph
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.provider[\"registry.terraform.io/digitalocean/digitalocean\"] (close)": starting visit (*terraform.graphNodeCloseProvider)
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn (expand)": starting visit (*terraform.nodeExpandOutput)
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.provider[\"registry.terraform.io/digitalocean/digitalocean\"] (close)": does not belong to any module instance
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn (expand)": does not belong to any module instance
2024-05-22T09:15:03.694-0400 [TRACE] Expanding output: adding module.domain.output.personal_company_domain_root_id as *terraform.NodeApplyableOutput
2024-05-22T09:15:03.694-0400 [TRACE] GRPCProvider: Close
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id (expand)": entering dynamic subgraph
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn (expand)": expanding dynamic subgraph
2024-05-22T09:15:03.694-0400 [TRACE] Expanding output: adding module.domain.output.personal_company_domain_root_urn as *terraform.NodeApplyableOutput
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id": starting visit (*terraform.NodeApplyableOutput)
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn (expand)": entering dynamic subgraph
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id": belongs to module.domain
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn": starting visit (*terraform.NodeApplyableOutput)
2024-05-22T09:15:03.694-0400 [TRACE] setValue: Saving value for module.domain.output.personal_company_domain_root_id in state
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn": belongs to module.domain
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id": visit complete
2024-05-22T09:15:03.694-0400 [TRACE] setValue: Saving value for module.domain.output.personal_company_domain_root_urn in state
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn": visit complete
2024-05-22T09:15:03.694-0400 [TRACE] vertex "root": starting visit (terraform.graphNodeRoot)
2024-05-22T09:15:03.694-0400 [TRACE] vertex "root": does not belong to any module instance
2024-05-22T09:15:03.694-0400 [TRACE] vertex "root": visit complete
2024-05-22T09:15:03.694-0400 [TRACE] vertex "root": starting visit (terraform.graphNodeRoot)
2024-05-22T09:15:03.694-0400 [TRACE] vertex "root": does not belong to any module instance
2024-05-22T09:15:03.694-0400 [TRACE] vertex "root": visit complete
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn (expand)": dynamic subgraph completed successfully
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_urn (expand)": visit complete
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id (expand)": dynamic subgraph completed successfully
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain.output.personal_company_domain_root_id (expand)": visit complete
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain (close)": starting visit (*terraform.nodeCloseModule)
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain (close)": does not belong to any module instance
2024-05-22T09:15:03.694-0400 [TRACE] vertex "module.domain (close)": visit complete
2024-05-22T09:15:03.694-0400 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-05-22T09:15:03.698-0400 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/digitalocean/digitalocean/2.38.0/linux_amd64/terraform-provider-digitalocean_v2.38.0 pid=55960
2024-05-22T09:15:03.698-0400 [DEBUG] provider: plugin exited
2024-05-22T09:15:03.698-0400 [TRACE] vertex "module.domain.provider[\"registry.terraform.io/digitalocean/digitalocean\"] (close)": visit complete
2024-05-22T09:15:03.863-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [DEBUG] DigitalOcean API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 201 Created
Content-Length: 245
Cf-Cache-Status: DYNAMIC
Cf-Ray: 887d12a45a8d05d6-IAD
Content-Type: application/json; charset=utf-8
Date: Wed, 22 May 2024 13:15:03 GMT
Ratelimit-Limit: 5000
Ratelimit-Remaining: 4787
Ratelimit-Reset: 1716387029
Server: cloudflare
Set-Cookie: [REDACTED]
X-Gateway: Edge-Gateway
X-Request-Id: a3efcb4b-636c-4d27-a634-5c274719b808
X-Response-From: service
X-Runtime: 0.012731

{
 "ssh_key": {
  "id": 42135543,
  "public_key": "[REDACTED]",
  "name": "some.email@email.com",
  "fingerprint": "REDACTED"
 }
}

-----------------------------------------------------: timestamp=2024-05-22T09:15:03.862-0400
2024-05-22T09:15:03.863-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [INFO] SSH Key: 42135543: timestamp=2024-05-22T09:15:03.863-0400
2024-05-22T09:15:03.863-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [DEBUG] DigitalOcean API Request Details:
---[ REQUEST ]---------------------------------------
GET /v2/account/keys/42135543 HTTP/1.1
Host: api.digitalocean.com
User-Agent: Terraform/1.8.3 godo/1.113.0
Accept: application/json
Accept-Encoding: gzip

-----------------------------------------------------: timestamp=2024-05-22T09:15:03.863-0400
2024-05-22T09:15:03.863-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [DEBUG] GET https://api.digitalocean.com/v2/account/keys/42135543: timestamp=2024-05-22T09:15:03.863-0400
2024-05-22T09:15:03.951-0400 [INFO]  provider.terraform-provider-digitalocean_v2.38.0: 2024/05/22 09:15:03 [DEBUG] DigitalOcean API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 404 Not Found
Cf-Cache-Status: DYNAMIC
Cf-Ray: 887d12a52b7805d6-IAD
Content-Type: application/json; charset=utf-8
Date: Wed, 22 May 2024 13:15:03 GMT
Ratelimit-Limit: 5000
Ratelimit-Remaining: 4786
Ratelimit-Reset: 1716387029
Server: cloudflare
Set-Cookie: [REDACTED]
X-Gateway: Edge-Gateway
X-Request-Id: 08b26945-d05a-4098-9fdb-ed6ce3d3caab
X-Response-From: service
X-Runtime: 0.003818

{
 "id": "not_found",
 "message": "The resource you were accessing could not be found."
}

-----------------------------------------------------: timestamp=2024-05-22T09:15:03.951-0400
2024-05-22T09:15:03.953-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Called downstream: tf_provider_addr=provider tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:838 @module=sdk.helper_schema tf_req_id=2bd7df7d-6233-0893-1345-eba3cef4a701 tf_resource_type=digitalocean_ssh_key timestamp=2024-05-22T09:15:03.952-0400
2024-05-22T09:15:03.953-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Received downstream response: @module=sdk.proto diagnostic_warning_count=0 tf_proto_version=5.3 tf_provider_addr=provider tf_req_duration_ms=259 tf_req_id=2bd7df7d-6233-0893-1345-eba3cef4a701 @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tf5serverlogging/downstream_request.go:37 diagnostic_error_count=0 tf_resource_type=digitalocean_ssh_key tf_rpc=ApplyResourceChange timestamp=2024-05-22T09:15:03.952-0400
2024-05-22T09:15:03.953-0400 [TRACE] provider.terraform-provider-digitalocean_v2.38.0: Served request: tf_provider_addr=provider tf_rpc=ApplyResourceChange @module=sdk.proto tf_proto_version=5.3 tf_req_id=2bd7df7d-6233-0893-1345-eba3cef4a701 tf_resource_type=digitalocean_ssh_key @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:831 timestamp=2024-05-22T09:15:03.953-0400
2024-05-22T09:15:03.954-0400 [TRACE] maybeTainted: module.ssh.digitalocean_ssh_key.personal_ssh_key encountered an error during creation, so it is now marked as tainted
2024-05-22T09:15:03.954-0400 [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/digitalocean/digitalocean" is in the global cache
2024-05-22T09:15:03.954-0400 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for module.ssh.digitalocean_ssh_key.personal_ssh_key
2024-05-22T09:15:03.954-0400 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: removing state object for module.ssh.digitalocean_ssh_key.personal_ssh_key
2024-05-22T09:15:03.954-0400 [TRACE] evalApplyProvisioners: module.ssh.digitalocean_ssh_key.personal_ssh_key is tainted, so skipping provisioning
2024-05-22T09:15:03.954-0400 [TRACE] maybeTainted: module.ssh.digitalocean_ssh_key.personal_ssh_key was already tainted, so nothing to do
2024-05-22T09:15:03.954-0400 [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/digitalocean/digitalocean" is in the global cache
2024-05-22T09:15:03.954-0400 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for module.ssh.digitalocean_ssh_key.personal_ssh_key
2024-05-22T09:15:03.954-0400 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: removing state object for module.ssh.digitalocean_ssh_key.personal_ssh_key
2024-05-22T09:15:03.954-0400 [DEBUG] State storage *remote.State declined to persist a state snapshot
2024-05-22T09:15:03.954-0400 [ERROR] vertex "module.ssh.digitalocean_ssh_key.personal_ssh_key" error: Provider produced inconsistent result after apply
2024-05-22T09:15:03.954-0400 [TRACE] vertex "module.ssh.digitalocean_ssh_key.personal_ssh_key": visit complete, with errors
2024-05-22T09:15:03.954-0400 [TRACE] dag/walk: upstream of "module.ssh.output.personal_ssh_key_id (expand)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "module.ssh.provider[\"registry.terraform.io/digitalocean/digitalocean\"] (close)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_droplet.minecraft (expand)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "module.ssh (close)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_droplet.minecraft" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_firewall.web (expand)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_reserved_ip.minecraft_static_ip (expand)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_firewall.web" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_volume_attachment.minecraft_volume_attachment (expand)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_reserved_ip.minecraft_static_ip" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_volume_attachment.minecraft_volume_attachment" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_reserved_ip_assignment.minecraft_static_ip_assignment (expand)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_record.minecraft_domain_a_record (expand)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_reserved_ip_assignment.minecraft_static_ip_assignment" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_project.personal_company_project (expand)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_record.minecraft_domain_a_record" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "digitalocean_project.personal_company_project" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/digitalocean/digitalocean\"] (close)" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] dag/walk: upstream of "root" errored, so skipping
2024-05-22T09:15:03.955-0400 [TRACE] terraform.contextPlugins: Schema for provider "registry.terraform.io/digitalocean/digitalocean" is in the global cache
2024-05-22T09:15:03.955-0400 [DEBUG] states/remote: state read serial is: 34; serial is: 34
2024-05-22T09:15:03.955-0400 [DEBUG] states/remote: state read lineage is: 307bb113-7e69-ccb7-d1a5-07277d5798e2; lineage is: 307bb113-7e69-ccb7-d1a5-07277d5798e2
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to module.ssh.digitalocean_ssh_key.personal_ssh_key,
│ provider
│ "module.ssh.provider[\"registry.terraform.io/digitalocean/digitalocean\"]"
│ produced an unexpected new value: Root object was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵
2024-05-22T09:15:03.961-0400 [DEBUG] DELETE https://gitlab.com/api/v4/projects/[REDACTED]/terraform/state/default/lock
2024-05-22T09:15:04.153-0400 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-05-22T09:15:04.153-0400 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-05-22T09:15:04.157-0400 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/digitalocean/digitalocean/2.38.0/linux_amd64/terraform-provider-digitalocean_v2.38.0 pid=55947
2024-05-22T09:15:04.157-0400 [DEBUG] provider: plugin exited
2024-05-22T09:15:04.158-0400 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/digitalocean/digitalocean/2.38.0/linux_amd64/terraform-provider-digitalocean_v2.38.0 pid=55969
2024-05-22T09:15:04.158-0400 [DEBUG] provider: plugin exited

Affected Resource(s)

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this. -->

Expected Behavior

An SSH Key should be created and Terraform should know about it in the state

Actual Behavior

The SSH key is created but Terraform believes it was not because of the race condition.

Steps to Reproduce

  1. terraform apply

Terraform Configuration Files

terraform {
  required_providers {
    digitalocean = {
      source  = "digitalocean/digitalocean"
      version = "~> 2.0"
    }
  }
}

provider "digitalocean" {
  token = var.do_token
}

variable "do_token" {}

resource "digitalocean_ssh_key" "terraform_ssh_key" {
  name       = "terraform-ssh-key"
  public_key = "SOME SSH KEY HERE"
}

resource "digitalocean_ssh_key" "personal_ssh_key" {
  name       = "some.email@email.com"
  public_key = "ANOTHER SSH KEY HERE"
}

output "terraform_ssh_key_id" {
  value       = digitalocean_ssh_key.terraform_ssh_key.id
  description = "Terraform ssh public key"
}

output "personal_ssh_key_id" {
  value       = digitalocean_ssh_key.personal_ssh_key.id
  description = "Personal SSH public key"
}

Terraform version Terraform v1.8.3 on linux_amd64

Debug Output Relevant output already pasted above

Additional Information Redacted response from manually running curl -XGET https://api.digitalocean.com/v2/account/keys/42135543 -H 'Authorization: Bearer $DO_TOKEN'

{
  "data": {
    "getSshKeys": {
      "pagination": {
        "page_count": "1",
        "__typename": "PaginationData"
      },
      "ssh_keys": [
        {
          "public_key": "[REDACTED]",
          "created_at": {
            "seconds": "1716383704",
            "__typename": "Timestamp"
          },
          "fingerprint": "[REDACTED]",
          "id": "42135543",
          "name": "some.email@email.com",
          "__typename": "SshKey"
        },
        {
          "public_key": "[REDACTED]",
          "created_at": {
            "seconds": "1716383634",
            "__typename": "Timestamp"
          },
          "fingerprint": "[REDACTED]",
          "id": "42135524",
          "name": "terraform-ssh-key",
          "__typename": "SshKey"
        }
      ],
      "__typename": "SshKeysResponse"
    }
  }
}

I have since deleted these keys manually, and while they are public keys I don't like posting any personal information :).

speedythesnail commented 4 months ago

Now that I searched Google for "digitalocean" "Terraform" "race condition", I found a related Issue here:

923