Skip to content

Access mulitple instances defined with a count block #233

@dantheperson

Description

@dantheperson

It seems limiting that the provider does not have a first class data/resource representation of a server instance, but rather the server instance is defined inside the provider block.

I am trying to grant roles on a database server that is created on GCP cloud using a count meta-argument.

It seems the only way to refer to multiple mysql server instances is to create multiple provider blocks with aliases for each server instance, and then use the provider meta-argument in resources to tie the resource to a particular server. In my case this does not work because the server instances are created with a count, and the provider block does not support the count meta-argument.

Am i missing something that would allow me to create a mysql_grant resource, with a count, that referenced each mysql server created with the same count variable.

How to tie these two resources together?

resource "google_sql_database_instance" "mysql_store" {
  count               = var.mysql_store_count
  name                = "store-${local.deployment_name}-${count.index}
}

resource "mysql_grant" "jdoe" {
  count     = var.mysql_store_count
  user       = mysql_user.jdoe.user
  host       = mysql_user.jdoe.host
  database   = "app"
  privileges = ["SELECT", "UPDATE"]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions