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

Support for database fork #1161

Closed
fabn opened this issue May 19, 2024 · 2 comments
Closed

Support for database fork #1161

fabn opened this issue May 19, 2024 · 2 comments

Comments

@fabn
Copy link

fabn commented May 19, 2024

Is your feature request related to a problem? Please describe.

I'd like to create a kind of blue green deployment in DO in order to fully replicate the infra I'd like to create a database fork from fresh data. Using cli this can be achieved via fork. It would be super useful to issue the same command using a terraform resource.

Describe the solution you'd like

Something like

resource "digitalocean_database_fork" "foo" {
  cluster_id = xxx
  region = "fra1"
  wait = true
}

Additional context

In the idea I'm having the wait flag is useful to create additional resources after fork has been provisioned.

@andrewsomething
Copy link
Member

andrewsomething commented Sep 5, 2024

Hi @fabn,

Sorry for the delayed response here. The doctl fork command is a helper that creates a new cluster from a backup. The digitalocean_database_cluster resource supports this with the backup_restore block.

https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/database_cluster#create-a-new-database-cluster-based-on-a-backup-of-an-existing-cluster

You'll just need the name of the original and be sure to set the size to something at least as large as the original.

resource "digitalocean_database_cluster" "forked-db" {
  name       = "forked-db"
  engine     = "pg"
  version    = "15"
  size       = "db-s-1vcpu-1gb"
  region     = "nyc3"
  node_count = 1

  backup_restore {
    database_name = "<name-of-original-db-cluster>"
  }
}

We first introduced support for this in v2.28.0.

As for the wait suggestions. We block until the database is create is completed. Terraform supports using a depends_on block if you need to ensure the order resources are created in.

https://developer.hashicorp.com/terraform/language/meta-arguments/depends_on

Hope that solves your issue. If I misunderstood the request, please feel free to reopen.

@fabn
Copy link
Author

fabn commented Sep 5, 2024

Yes, i discovered that some time after I created the issue and i forgot to close it. Thanks anyway.

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

No branches or pull requests

2 participants