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 setting url in sql_migrate ressource #52

Open
Exchizz opened this issue Feb 17, 2022 · 6 comments
Open

Support setting url in sql_migrate ressource #52

Exchizz opened this issue Feb 17, 2022 · 6 comments

Comments

@Exchizz
Copy link

Exchizz commented Feb 17, 2022

Hi,

Great provider ! I'm really missing to be able to specify the url in the ressource.
Basically I want to be able to do something like this:

locals {
  data = {
      "DB_A" = {
        "url" = "sql url goes here"
         "up_script" = "a/b/up.sql"
         "down_script" = "a/b/down.sql"
       }
      "DB_B" = {
        "url" = "sql url goes here"
         "up_script" = "a/b/up.sql"
         "down_script" = "a/b/down.sql"
       }
  }
}
resource "sql_migrate" "schema" {
  for_each = local.data
  url = each.value.url
  migration {
    up   = each.value.sql_up 
    down = each.value.sql_down
 }
}

Thanks in advance :)

@bittrance
Copy link

I just want to underline that this is a requirement for using this provider in many public cloud use cases. In such use cases, the database will be created within the same Terraform configuration as the SQL provider is invoked and the database URL cannot be known in advance. In such use cases, the URL will have to be built from properties read from the database resource.

@cosmotek
Copy link

I just ran into the same issue. Until I can provide a URL in the resource from a terraform var, I will be using local_exec :(

@esalter
Copy link

esalter commented Dec 16, 2022

I love the concept of this provider but we would need this too - we provision db instances automatically and would like to run some post-setup SQL against the instance. Current url declaration in the provider makes that impossible.

@ei-grad
Copy link

ei-grad commented Aug 7, 2024

The ability to specify a URL will not align with the Terraform providers concept. What behavior would you expect if the URL is changed in the sql_migrate resource?

Additionally, the use case of "provision database, then apply migration" would not work in a single Terraform execution, because it would fail at the plan stage. Should sql_migrate prepare a plan? How could it do that if there is no URL?

@ei-grad
Copy link

ei-grad commented Aug 7, 2024

provider "sql" {
  alias = "DB_A"
  url = "sql url goes here"
}

resource "sql_migrate" "a" {
  provider = sql.DB_A
  migration {
    up   = "a.sql.up"
    down = "a.sql.down"
  }
}

provider "sql" {
  alias = "DB_B"
  url = "sql url goes here"
}

resource "sql_migrate" "b" {
  provider = sql.DB_B
  migration {
    up   = "b.sql.up"
    down = "b.sql.down"
  }
}

@ei-grad
Copy link

ei-grad commented Aug 7, 2024

Follow opentofu/opentofu#300 for a proper solution to cases like this.

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

5 participants