terraform-provider-digitalocean icon indicating copy to clipboard operation
terraform-provider-digitalocean copied to clipboard

Support for sql_require_primary_key in digitalocean_database_cluster

Open spantaleev opened this issue 1 year ago • 1 comments

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

I have an application which requires a MySQL database instance running with sql_require_primary_key=false.

The default value for a Digital Ocean MySQL database is true.

Changing the sql_require_primary_key configuration via the API is possible: curl -H 'Authorization: Bearer XXX' -XPATCH --data '{"config": {"sql_require_primary_key": false}}' https://api.digitalocean.com/v2/databases/{YOUR_DATABASE_CLUSER_ID}/config).

It'd be more convenient if this could be done via the digitalocean_database_cluster resource.

Describe the solution you'd like

A new sql_require_primary_key field may be added to the digitalocean_database_cluster resource which would influence the sql_require_primary_key configuration setting.

Describe alternatives you've considered

For now, I'm changing sql_require_primary_key manually via the API, outside of Terraform.

My manual changes do not seem to get undone by subsequent Terraform runs, so it's usable.

spantaleev avatar Jun 17 '23 13:06 spantaleev

I have the same problem and I solved it with a temporary workaround using the Mastercard/restapi provider:

# Configure the RestAPI provider
provider "restapi" {
  uri = "https://api.digitalocean.com/"

  headers = {
    "Authorization" = format("Bearer %s", var.do_token)
    "Content-Type"  = "application/json"
  }

  create_returns_object = false
  write_returns_object = false
  debug = true
}

resource "restapi_object" "myproject-mysql-extra-config" {
  path = "/v2/databases/{id}/config"
  read_path = "/v2/databases/{id}/config"
  create_method  = "PATCH"
  create_path = "/v2/databases/{id}/config"
  update_method  = "PATCH"
  update_path = "/v2/databases/{id}/config"
  destroy_method = "GET"
  destroy_path = "/v2/databases/{id}/config"
  id_attribute = digitalocean_database_cluster.myproject-mysql.id
  object_id = digitalocean_database_cluster.myproject-mysql.id
  data = "{\"config\": { \"sql_require_primary_key\": false }}"
}

It would be great to have a new digitalocean_database_config resource so that it could be possible to do this:

resource "digitalocean_database_config" "database-config-example" {
  cluster_id = digitalocean_database_cluster.mysql-example.id
  sql_require_primary_key = false
}

Right now the DO API has two endpoints:

  • GET (Retrieve an Existing Database Cluster Configuration) https://docs.digitalocean.com/reference/api/api-reference/#operation/databases_get_config
  • PATCH (Update the Database Configuration for an Existing Database) https://docs.digitalocean.com/reference/api/api-reference/#operation/databases_patch_config

If these two endpoints are enough to create the new resource I am open to create a new PR with this new resource and at least the sql_require_primary_key parameter. Later it could be upgraded with other config parameters.

dvigueras avatar Aug 14 '23 09:08 dvigueras