linode/terraform-provider-linode

[Feature]:Workaround for Error: Cycle in linode_database_mysql

Closed this issue · 1 comments

Description

I would like the allow_list of linode_database_mysql to be a separate module.
Because we want to create a Database, create an Instance, allow the Instance's IP, and so on.

I use StackScript to install Wordpress.
In doing so, I want to use ManagedDB and allow only the IP of the instance created.

Attempting to do the current code will result in a circular reference error.

Error: Cycle: linode_instance.wordpress, linode_database_mysql.db

Here are the results of the graph.

 terraform graph -draw-cycles | dot -Tpng > graph.png

graph_png

New or Affected Terraform Resources

linode_database_mysql

Potential Terraform Configuration

resource "linode_database_mysql" "db" {
  count = var.node_count
  label = "database"
  engine_id = var.db.engine_id
  region = var.region
  type = var.db.type
  cluster_size = 1

# I want to make it a separate module.
  allow_list = ["${element(linode_instance.wordpress.*.private_ip_address, count.index)}/32"]
}

resource "linode_instance" "wordpress" {
  count = var.node_count
  label = "wordpress-managed-${count.index + 1}"
  image = var.wordpress.image
  region = var.region
  type = var.wordpress.type
  authorized_keys = ["${chomp(file(var.public_ssh_key))}"]

  group = var.wordpress.group
  swap_size = 256
  root_pass = random_string.password.result
  private_ip = true

  stackscript_id = var.stackscript_id
  stackscript_data = {
    fqdn = var.stackscript_data.fqdn
    db_password = linode_database_mysql.db.0.root_password
    dbroot_password = linode_database_mysql.db.0.root_password
    db_host = linode_database_mysql.db.0.host_secondary
    site_title = var.stackscript_data.site_title
    wp_admin = var.stackscript_data.wp_admin
    wp_password = var.stackscript_data.wp_password
    soa_email_address = var.stackscript_data.soa_email_address
  }
}

Hello, thanks for the feature request!

This functionality has been merged and will be available in our next release. You will be able to externally configure a Database's allow_list through the linode_database_access_controls resource. At the moment you will only be able to specify one linode_database_access_controls resource per-database, but hopefully this will help mitigate the cyclic dependency you're running into.

Let us know if you have any other issues or suggestions 🙂