From bca3395cc89e87dede6ad2ef79e0db71ff166031 Mon Sep 17 00:00:00 2001 From: Chema Date: Tue, 15 Feb 2022 20:59:18 +0100 Subject: [PATCH] fix s/databases/database --- .../{databases.md => database.md} | 8 +-- .../data-source.tf | 4 +- pkg/datasources/{databases.go => database.go} | 14 +++--- pkg/datasources/database_acceptance_test.go | 49 +++++++++++++++++++ pkg/datasources/databases_acceptance_test.go | 49 ------------------- pkg/provider/provider.go | 2 +- 6 files changed, 63 insertions(+), 63 deletions(-) rename docs/data-sources/{databases.md => database.md} (78%) rename examples/data-sources/{snowflake_databases => snowflake_database}/data-source.tf (54%) rename pkg/datasources/{databases.go => database.go} (86%) create mode 100644 pkg/datasources/database_acceptance_test.go delete mode 100644 pkg/datasources/databases_acceptance_test.go diff --git a/docs/data-sources/databases.md b/docs/data-sources/database.md similarity index 78% rename from docs/data-sources/databases.md rename to docs/data-sources/database.md index b88b4c668e0..4820882a14f 100644 --- a/docs/data-sources/databases.md +++ b/docs/data-sources/database.md @@ -1,22 +1,22 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "snowflake_databases Data Source - terraform-provider-snowflake" +page_title: "snowflake_database Data Source - terraform-provider-snowflake" subcategory: "" description: |- --- -# snowflake_databases (Data Source) +# snowflake_database (Data Source) ## Example Usage ```terraform -data "snowflake_databases" "this" {} +data "snowflake_database" "this" {} resource "snowflake_database" "backups" { - for_each = { for x in data.snowflake_databases.this.databases: x.name => x } + for_each = { for x in data.snowflake_database.this.databases: x.name => x } name = "BACKUP_${each.key}" comment = "Backup of ${each.key} - ${each.value.comment}" diff --git a/examples/data-sources/snowflake_databases/data-source.tf b/examples/data-sources/snowflake_database/data-source.tf similarity index 54% rename from examples/data-sources/snowflake_databases/data-source.tf rename to examples/data-sources/snowflake_database/data-source.tf index 01e3d1f9acd..6457d20fbd3 100644 --- a/examples/data-sources/snowflake_databases/data-source.tf +++ b/examples/data-sources/snowflake_database/data-source.tf @@ -1,7 +1,7 @@ -data "snowflake_databases" "this" {} +data "snowflake_database" "this" {} resource "snowflake_database" "backups" { - for_each = { for x in data.snowflake_databases.this.databases: x.name => x } + for_each = { for x in data.snowflake_database.this.databases: x.name => x } name = "BACKUP_${each.key}" comment = "Backup of ${each.key} - ${each.value.comment}" diff --git a/pkg/datasources/databases.go b/pkg/datasources/database.go similarity index 86% rename from pkg/datasources/databases.go rename to pkg/datasources/database.go index 0f262409023..67aafc2abff 100644 --- a/pkg/datasources/databases.go +++ b/pkg/datasources/database.go @@ -10,7 +10,7 @@ import ( "github.com/jmoiron/sqlx" ) -var databasesSchema = map[string]*schema.Schema{ +var databaseSchema = map[string]*schema.Schema{ "databases": { Type: schema.TypeList, Computed: true, @@ -58,16 +58,16 @@ var databasesSchema = map[string]*schema.Schema{ }, } -// Databases the Snowflake current account resource -func Databases() *schema.Resource { +// Database the Snowflake current databases resource +func Database() *schema.Resource { return &schema.Resource{ - Read: ReadDatabases, - Schema: databasesSchema, + Read: ReadDatabase, + Schema: databaseSchema, } } -// ReadDatabases read the current snowflake account information -func ReadDatabases(d *schema.ResourceData, meta interface{}) error { +// ReadDatabase read the current snowflake databases information +func ReadDatabase(d *schema.ResourceData, meta interface{}) error { db := meta.(*sql.DB) dbx := sqlx.NewDb(db, "snowflake") dbs, err := snowflake.ListDatabases(dbx) diff --git a/pkg/datasources/database_acceptance_test.go b/pkg/datasources/database_acceptance_test.go new file mode 100644 index 00000000000..ca9fe8e9545 --- /dev/null +++ b/pkg/datasources/database_acceptance_test.go @@ -0,0 +1,49 @@ +package datasources_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestDatabase(t *testing.T) { + databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) + comment := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) + resource.ParallelTest(t, resource.TestCase{ + + Providers: providers(), + Steps: []resource.TestStep{ + { + Config: databases(databaseName, comment), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.snowflake_database.t", "databases.#"), + resource.TestCheckResourceAttr("data.snowflake_database.t", "databases.#", "1"), + resource.TestCheckResourceAttr("data.snowflake_database.t", "databases.0.name", databaseName), + resource.TestCheckResourceAttr("data.snowflake_database.t", "databases.0.comment", comment), + resource.TestCheckResourceAttrSet("data.snowflake_database.t", "databases.0.created_on"), + resource.TestCheckResourceAttrSet("data.snowflake_database.t", "databases.0.owner"), + resource.TestCheckResourceAttrSet("data.snowflake_database.t", "databases.0.retention_time"), + resource.TestCheckResourceAttrSet("data.snowflake_database.t", "databases.0.options"), + resource.TestCheckResourceAttrSet("data.snowflake_database.t", "databases.0.origin"), + resource.TestCheckResourceAttrSet("data.snowflake_database.t", "databases.0.is_current"), + resource.TestCheckResourceAttrSet("data.snowflake_database.t", "databases.0.is_default"), + ), + }, + }, + }) +} + +func databases(databaseName, comment string) string { + return fmt.Sprintf(` + resource snowflake_database "test_database" { + name = "%v" + comment = "%v" + } + data snowflake_database "t" { + depends_on = [snowflake_database.test_database] + } + `, databaseName, comment) +} diff --git a/pkg/datasources/databases_acceptance_test.go b/pkg/datasources/databases_acceptance_test.go deleted file mode 100644 index ff0b1be633d..00000000000 --- a/pkg/datasources/databases_acceptance_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package datasources_test - -import ( - "fmt" - "strings" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestDatabases(t *testing.T) { - databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - comment := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - resource.ParallelTest(t, resource.TestCase{ - - Providers: providers(), - Steps: []resource.TestStep{ - { - Config: databases(databaseName, comment), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.snowflake_databases.t", "databases.#"), - resource.TestCheckResourceAttr("data.snowflake_databases.t", "databases.#", "1"), - resource.TestCheckResourceAttr("data.snowflake_databases.t", "databases.0.name", databaseName), - resource.TestCheckResourceAttr("data.snowflake_databases.t", "databases.0.comment", comment), - resource.TestCheckResourceAttrSet("data.snowflake_databases.t", "databases.0.created_on"), - resource.TestCheckResourceAttrSet("data.snowflake_databases.t", "databases.0.owner"), - resource.TestCheckResourceAttrSet("data.snowflake_databases.t", "databases.0.retention_time"), - resource.TestCheckResourceAttrSet("data.snowflake_databases.t", "databases.0.options"), - resource.TestCheckResourceAttrSet("data.snowflake_databases.t", "databases.0.origin"), - resource.TestCheckResourceAttrSet("data.snowflake_databases.t", "databases.0.is_current"), - resource.TestCheckResourceAttrSet("data.snowflake_databases.t", "databases.0.is_default"), - ), - }, - }, - }) -} - -func databases(databaseName, comment string) string { - return fmt.Sprintf(` - resource snowflake_database "test_database" { - name = "%v" - comment = "%v" - } - data snowflake_databases "t" { - depends_on = [snowflake_database.test_database] - } - `, databaseName, comment) -} diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index aa6dea17d2e..53ff420bd4e 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -235,7 +235,7 @@ func getDataSources() map[string]*schema.Resource { "snowflake_row_access_policies": datasources.RowAccessPolicies(), "snowflake_functions": datasources.Functions(), "snowflake_procedures": datasources.Procedures(), - "snowflake_databases": datasources.Databases(), + "snowflake_database": datasources.Database(), } return dataSources