Skip to content
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

Creating PostgreSQL DBs and users still fails randomly #493

Open
gfmio opened this issue Sep 24, 2020 · 7 comments
Open

Creating PostgreSQL DBs and users still fails randomly #493

gfmio opened this issue Sep 24, 2020 · 7 comments

Comments

@gfmio
Copy link

gfmio commented Sep 24, 2020

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

Terraform v0.13.3

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

Affected Resource(s)

Please list the resources as a list, for example:

  • opc_instance

  • opc_storage_volume

  • digitalocean_database_cluster

  • digitalocean_database_user

  • digitalocean_database_database

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

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.
# App DB

locals {
  db_name = "app"
  db_user = "app"
}

# DB cluster

resource "digitalocean_database_cluster" "app_db_cluster" {
  name                 = "${var.name}-app-db-cluster"
  engine               = "pg"
  version              = "12"
  size                 = "db-s-1vcpu-1gb"
  region               = var.region
  node_count           = 1
  private_network_uuid = digitalocean_vpc.vpc.id
}

# DB

resource "digitalocean_database_db" "app_db" {
  cluster_id = digitalocean_database_cluster.app_db_cluster.id
  name       = local.db_name
}

# DB user

resource "digitalocean_database_user" "db_user" {
  cluster_id = digitalocean_database_cluster.app_db_cluster.id
  name       = local.db_user
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.

When the resources get created, I sometimes get the following error:

Error: Provider produced inconsistent result after apply

When applying changes to digitalocean_database_user.db_user, provider
"registry.terraform.io/-/digitalocean" produced an unexpected new value for
was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

What should have happened?

The resources get created without fail.

Actual Behavior

What actually happened?

The resource creation sometimes throws the above error. I think this might be some kind of race condition? Because when I check manually in the UI, everything has been created and looks fine.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

@gfmio gfmio changed the title Creating PostgreSQL DBs and users randomly still fails Creating PostgreSQL DBs and users still fails randomly Sep 26, 2020
@adelmoradian
Copy link

same issue when creating a mysql cluster and db users.
I'm using provider version 2.3.0 and terraform 0.13.5

@indrif
Copy link

indrif commented Mar 25, 2022

Having similar errors when creating/ deleting databases and users within an existing cluster. Any update on this?

@cikupin
Copy link

cikupin commented Apr 19, 2022

It is still happening to me when I create MongoDB database users using list and for_each.

I use provider 2.19.0, terraform 1.1.4, and terragrunt 0.36.0.

@c-w
Copy link

c-w commented Jul 28, 2022

Happening here too for Postgres DBs on provider v2.21.0 terraform v1.1.9.

@Nuxij
Copy link

Nuxij commented Jul 28, 2022

I just started getting this issue randomly..

resource "digitalocean_database_cluster" "saas" {
    name                 = var.cluster_name
    engine               = "mysql"
    version              = "8"
    size                 = "db-s-1vcpu-1gb"
    region               = var.region
    node_count           = 1
    private_network_uuid = digitalocean_vpc.saas.id
}

resource "digitalocean_database_user" "saas" {
  cluster_id = digitalocean_database_cluster.saas.id
  name       = "saas-user"
  mysql_auth_plugin = "mysql_native_password"
}

resource "digitalocean_database_db" "saas" {
  cluster_id = digitalocean_database_cluster.saas.id
  name       = "saas"
}

And I get this error:

digitalocean_database_db.saas: Creating...
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to digitalocean_database_db.saas, provider
│ "provider[\"registry.terraform.io/digitalocean/digitalocean\"]" produced an
│ unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ ow

No other clues as to what could be causing this - one minute it worked. Next minute it doesn't :(

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

@Mayeu
Copy link

Mayeu commented Nov 28, 2022

We are also experiencing this on Postgres and the last version of the provider (2.25.2).

@SkeLLLa
Copy link

SkeLLLa commented May 19, 2023

I've also managed to reproduce this. So in order to have higher chances you may need to create multiple users at the same terraform apply stage. It looks like that it's caused by some race condition or API loadbalancing, e.g. when resource created on one instance of DO API, on the next request it's still not properly propagated to other.

So as a workaround I suggest to implement few retries with some delays:

POST -> create
GET -> get resource by id
[retry if GET failed]
GET -> get resource by id
[retry if GET failed]
GET -> get resource by id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants