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

Database from share using organization.account as a provider

Open marcin-vt opened this issue 2 years ago • 6 comments

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

Following new snowflake release, when creating a database from share instead of account locator you can specify source as ORGANIZATION.ACCOUNT.SHARE. This is not supported by current (0.37.1) version of the provider. Adding ORGANIZATION.ACCOUNT in the provider field results in error, because of the quoting here.

Describe the solution you'd like

The clearest for me would be to add fields organization, account and account_locator, that would replace provider in snowflake_database resource. Where user has to provide either organization and account or account_locator.

Describe alternatives you've considered

Could also live with provider properly handling ORGANIZATION.ACCOUNT format.

Additional context

marcin-vt avatar Jul 08 '22 06:07 marcin-vt

This is an issue for my use case as well. It looks like #1090 also addressed this as well, but was closed as using a fully-qualified name seemed to the be the preference over . I'd love to help here if I can.

@sfc-gh-swinkler @marcin-vt @gouline Is anyone actively working on this or should I throw my own PR into the mix?

peteigel avatar Jul 20 '22 20:07 peteigel

It is supported, you have to use escaped middle quotes as discussed in #1090 and illustrated in the from_replica example in snowflake_database.

resource "snowflake_database" "database" {
  name    = "DATABASE_NAME"
  from_share = {
    provider = "ORGANIZATION\".\"ACCOUNT"
    share    = "SHARE"
  }
}

gouline avatar Jul 20 '22 22:07 gouline

Thanks for the answer @gouline. It does work - just look a bit awkward... Also as a side remark when creating database from share, comment is ignored. It is applied when running for the second time.

btw. @gouline are you working on moving from from_share to fully qualified names? If so I guess I can close the PR #1114 .

marcin-vt avatar Jul 21 '22 17:07 marcin-vt

It does work - just look a bit awkward...

I agree, but it's consistent with from_replica and that's the preference of the maintainers.

Also as a side remark when creating database from share, comment is ignored. It is applied when running for the second time.

Good point, the create statement just runs create database from share and nothing else. You're welcome to contribute a fix, just need to build that create statement iteratively (like in most other resources).

are you working on moving from from_share to fully qualified names? If so I guess I can close the PR #1114 .

Provider is already a fully-qualified name (i.e. ORGANIZATION\".\"ACCOUNT). The only change would be to abolish the map in favour of a full string, like from_replica, but that's a breaking change for little benefit, so I'm not working on it.

gouline avatar Jul 22 '22 00:07 gouline

@gouline makes a good point. We need to update the documentation to make this more clear, however.

sfc-gh-swinkler avatar Aug 08 '22 21:08 sfc-gh-swinkler

Agreed on documentation, I had to look at the code to figure it out. @marcin-vt also raised a bug here that comment isn't getting included in the create statement (only update).

Happy to raise a PR with those 2 fixes, unless somebody else wants to.

gouline avatar Aug 08 '22 23:08 gouline