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

feat: use SDK in schema resource and datasource #2082

Merged
merged 5 commits into from
Oct 16, 2023

Conversation

sfc-gh-jcieslak
Copy link
Collaborator

No description provided.

@github-actions
Copy link

Integration tests failure for 7504035d47a34d65c608f530c94d68f16d69e3ed

@github-actions
Copy link

Integration tests failure for fbd0946207cc07f5c81aac42e393ec0f97c54765

}
return sdk.NewDatabaseObjectIdentifier(v["database"].(string), v["name"].(string))
}
return sdk.NewAccountObjectIdentifier(v["name"].(string))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. I think tags are database or database+schema objects and without them it cannot be created / retrieved (unless there's active database or database+schema in the client session), so I should return error here. What do you think ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I think tags are indeed on schema level: https://docs.snowflake.com/en/user-guide/object-tagging#what-is-a-tag and I guess this should be the only option here.

Both schema and database are required in schema resource definition, so it is safe to assume they will be present here.

@scottwinkler, can you also chip in?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tags are indeed schema level objects. although it might appear like you could create a tag without a database or schema, since you can do create tag "my_tag", this uses whatever your current database and schema are set to in the given session

@github-actions
Copy link

Integration tests failure for 515366df0fc207157436c88cfee01b04a97bc21e

@github-actions
Copy link

Integration tests success for b7ae972fcad1aaf9a7f6e69770ee1a6520faee1f

@sfc-gh-jcieslak sfc-gh-jcieslak marked this pull request as ready for review September 29, 2023 14:01
@github-actions
Copy link

Integration tests failure for 64e177215e2115bd2a74d699ff98db85d51684e7

@github-actions
Copy link

github-actions bot commented Oct 2, 2023

Integration tests failure for 9a437900ca83e6d55aab906e4edbbbc8a493f0ce

1 similar comment
@github-actions
Copy link

github-actions bot commented Oct 2, 2023

Integration tests failure for 9a437900ca83e6d55aab906e4edbbbc8a493f0ce

pkg/datasources/schemas.go Outdated Show resolved Hide resolved
pkg/resources/schema.go Outdated Show resolved Hide resolved
pkg/resources/helpers.go Outdated Show resolved Hide resolved
}
return sdk.NewDatabaseObjectIdentifier(v["database"].(string), v["name"].(string))
}
return sdk.NewAccountObjectIdentifier(v["name"].(string))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I think tags are indeed on schema level: https://docs.snowflake.com/en/user-guide/object-tagging#what-is-a-tag and I guess this should be the only option here.

Both schema and database are required in schema resource definition, so it is safe to assume they will be present here.

@scottwinkler, can you also chip in?

return sdk.NewAccountObjectIdentifier(v["name"].(string))
}

func getPropertyTags(d *schema.ResourceData, key string) []sdk.TagAssociation {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the plan for tags and tags associations @scottwinkler? I can see that now they are supported in two places: for some resource, like schema here, they have "tag": tagReferenceSchema specified, but tagReferenceSchema has Deprecated: "Use the 'snowflake_tag_association' resource instead.".

So I believe that for now we want to support both options, and with V1 we cut out this deprecated option, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well i think it is a similar problem to the snowflake_parameters vs having the same attribute be on a resource. We also have to weigh the downside of basically doubling the number of resources, if customers want to tag every resource. i didn't like the implementation of tag blocks previously, because it was difficult to know when the order changed, and also it made for really long configuration code, but I could see maybe adding them back later with a slightly different syntax, e.g.:

snowflake_database "d" {
....
tags = [
{
tag_name = ""
tag_value = ""
},
{
tag_name = ""
tag_value = ""
},
...
]
}

That being said, if we add tags back in it would be problematic for people who use the existing tag association resource. They would need to set ignore_changes = ["tags"] on every resource which uses tags so as not dissociate every tag they had set. https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes. At the time it was too complicated to have a tags block on every resource, which is why it was made into its own resource. Now that we have a more stable API, I'm not sure its beneficial anymore.

pkg/resources/helpers.go Show resolved Hide resolved
pkg/resources/schema.go Outdated Show resolved Hide resolved
pkg/resources/helpers_test.go Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Oct 6, 2023

Integration tests success for c0303245a7b58fa2f0a11ca7116d20ae62929300

@github-actions
Copy link

github-actions bot commented Oct 6, 2023

Integration tests failure for 233f3e763a4ef36c1014318ca29f0a1db95254ad

@github-actions
Copy link

github-actions bot commented Oct 6, 2023

Integration tests failure for 32b8f71da47fcdefe7abb83da5477c21a045de29

@github-actions
Copy link

github-actions bot commented Oct 6, 2023

Integration tests success for 32b8f71da47fcdefe7abb83da5477c21a045de29

@github-actions
Copy link

github-actions bot commented Oct 9, 2023

Integration tests failure for cc751347d502d597809e3209151cede438c20e8d

1 similar comment
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

Integration tests failure for cc751347d502d597809e3209151cede438c20e8d

}
return sdk.NewDatabaseObjectIdentifier(v["database"].(string), v["name"].(string))
}
return sdk.NewAccountObjectIdentifier(v["name"].(string))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tags are indeed schema level objects. although it might appear like you could create a tag without a database or schema, since you can do create tag "my_tag", this uses whatever your current database and schema are set to in the given session

return sdk.NewAccountObjectIdentifier(v["name"].(string))
}

func getPropertyTags(d *schema.ResourceData, key string) []sdk.TagAssociation {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well i think it is a similar problem to the snowflake_parameters vs having the same attribute be on a resource. We also have to weigh the downside of basically doubling the number of resources, if customers want to tag every resource. i didn't like the implementation of tag blocks previously, because it was difficult to know when the order changed, and also it made for really long configuration code, but I could see maybe adding them back later with a slightly different syntax, e.g.:

snowflake_database "d" {
....
tags = [
{
tag_name = ""
tag_value = ""
},
{
tag_name = ""
tag_value = ""
},
...
]
}

That being said, if we add tags back in it would be problematic for people who use the existing tag association resource. They would need to set ignore_changes = ["tags"] on every resource which uses tags so as not dissociate every tag they had set. https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes. At the time it was too complicated to have a tags block on every resource, which is why it was made into its own resource. Now that we have a more stable API, I'm not sure its beneficial anymore.

@github-actions
Copy link

Integration tests success for cc751347d502d597809e3209151cede438c20e8d

@github-actions
Copy link

Integration tests failure for 63747da90ba1bbeb404acb477d8c0012c44c9a43

@github-actions
Copy link

Integration tests failure for 02ee64c603ddb908d3a7548e973980bf3139d559

@github-actions
Copy link

Integration tests failure for dbd3a5528851cf3c0936942f5c1618f7c3528521

@github-actions
Copy link

Integration tests success for b1c0c88c91f1ed6274edbbee511d2e1b6766cba7

@sfc-gh-jcieslak sfc-gh-jcieslak merged commit f7d0d97 into main Oct 16, 2023
8 checks passed
@sfc-gh-jcieslak sfc-gh-jcieslak deleted the use-schemas-from-sdk branch October 16, 2023 06:26
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

Successfully merging this pull request may close these issues.

None yet

3 participants