From 94a70997c3129c5af83c5c1e56e7cc068286cf1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Cie=C5=9Blak?= Date: Tue, 10 Dec 2024 09:21:13 +0100 Subject: [PATCH 1/2] Add account data source --- MIGRATION_GUIDE.md | 24 +++ docs/data-sources/accounts.md | 65 +++++++- .../snowflake_accounts/data-source.tf | 48 ++++++ .../account_show_output_ext.go | 112 +++++++++++++ pkg/datasources/accounts.go | 152 ++++-------------- pkg/datasources/accounts_acceptance_test.go | 82 +++++++++- 6 files changed, 351 insertions(+), 132 deletions(-) create mode 100644 examples/data-sources/snowflake_accounts/data-source.tf create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/account_show_output_ext.go diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index dbfef7d7f6..e85a99a66d 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -9,6 +9,30 @@ across different versions. ## v0.99.0 ➞ v0.100.0 +### snowflake_accounts data source changes +New filtering options: +- `with_history` + +New output fields +- `show_output` + +Breaking changes: +- `pattern` renamed to `like` +- `accounts` field now organizes output of show under `show_output` field and the output of show parameters under `parameters` field. + +Before: +```terraform +output "simple_output" { + value = data.snowflake_accounts.test.accounts[0].account_name +} +``` +After: +```terraform +output "simple_output" { + value = data.snowflake_accounts.test.accounts[0].show_output[0].account_name +} +``` + ### snowflake_tag_association resource changes #### *(behavior change)* new id format In order to provide more functionality for tagging objects, we have changed the resource id from `"TAG_DATABASE"."TAG_SCHEMA"."TAG_NAME"` to `"TAG_DATABASE"."TAG_SCHEMA"."TAG_NAME"|TAG_VALUE|OBJECT_TYPE`. This allows to group tags associations per tag ID, tag value and object type in one resource. diff --git a/docs/data-sources/accounts.md b/docs/data-sources/accounts.md index 7a739538ec..3d7728649c 100644 --- a/docs/data-sources/accounts.md +++ b/docs/data-sources/accounts.md @@ -2,25 +2,77 @@ page_title: "snowflake_accounts Data Source - terraform-provider-snowflake" subcategory: "" description: |- - + Data source used to get details of filtered accounts. Filtering is aligned with the current possibilities for SHOW ACCOUNTS https://docs.snowflake.com/en/sql-reference/sql/show-accounts query. The results of SHOW are encapsulated in one output collection accounts. --- # snowflake_accounts (Data Source) +Data source used to get details of filtered accounts. Filtering is aligned with the current possibilities for [SHOW ACCOUNTS](https://docs.snowflake.com/en/sql-reference/sql/show-accounts) query. The results of SHOW are encapsulated in one output collection `accounts`. +## Example Usage +```terraform +# Simple usage +data "snowflake_accounts" "simple" { +} +output "simple_output" { + value = data.snowflake_accounts.simple.accounts +} + +# Filtering (like) +data "snowflake_accounts" "like" { + like = "account-name" +} + +output "like_output" { + value = data.snowflake_accounts.like.accounts +} + +# With history +data "snowflake_accounts" "with_history" { + with_history = true +} + +output "with_history_output" { + value = data.snowflake_accounts.like.accounts +} + +# Ensure the number of accounts is equal to at least one element (with the use of postcondition) +data "snowflake_accounts" "assert_with_postcondition" { + like = "account-name" + lifecycle { + postcondition { + condition = length(self.accounts) > 0 + error_message = "there should be at least one account" + } + } +} + +# Ensure the number of accounts is equal to at exactly one element (with the use of check block) +check "account_check" { + data "snowflake_accounts" "assert_with_check_block" { + like = "account-name" + } + + assert { + condition = length(data.snowflake_accounts.assert_with_check_block.accounts) == 1 + error_message = "accounts filtered by '${data.snowflake_accounts.assert_with_check_block.like}' returned ${length(data.snowflake_accounts.assert_with_check_block.accounts)} accounts where one was expected" + } +} +``` ## Schema ### Optional -- `pattern` (String) Specifies an account name pattern. If a pattern is specified, only accounts matching the pattern are returned. +- `like` (String) Filters the output with **case-insensitive** pattern, with support for SQL wildcard characters (`%` and `_`). +- `with_history` (Boolean) Includes dropped accounts that have not yet been deleted. ### Read-Only -- `accounts` (List of Object) List of all the accounts available in the organization. (see [below for nested schema](#nestedatt--accounts)) +- `accounts` (List of Object) Holds the aggregated output of all accounts details queries. (see [below for nested schema](#nestedatt--accounts)) - `id` (String) The ID of this resource. @@ -28,6 +80,13 @@ description: |- Read-Only: +- `show_output` (List of Object) (see [below for nested schema](#nestedobjatt--accounts--show_output)) + + +### Nested Schema for `accounts.show_output` + +Read-Only: + - `account_locator` (String) - `account_locator_url` (String) - `account_name` (String) diff --git a/examples/data-sources/snowflake_accounts/data-source.tf b/examples/data-sources/snowflake_accounts/data-source.tf new file mode 100644 index 0000000000..5504b4d043 --- /dev/null +++ b/examples/data-sources/snowflake_accounts/data-source.tf @@ -0,0 +1,48 @@ +# Simple usage +data "snowflake_accounts" "simple" { +} + +output "simple_output" { + value = data.snowflake_accounts.simple.accounts +} + +# Filtering (like) +data "snowflake_accounts" "like" { + like = "account-name" +} + +output "like_output" { + value = data.snowflake_accounts.like.accounts +} + +# With history +data "snowflake_accounts" "with_history" { + with_history = true +} + +output "with_history_output" { + value = data.snowflake_accounts.like.accounts +} + +# Ensure the number of accounts is equal to at least one element (with the use of postcondition) +data "snowflake_accounts" "assert_with_postcondition" { + like = "account-name" + lifecycle { + postcondition { + condition = length(self.accounts) > 0 + error_message = "there should be at least one account" + } + } +} + +# Ensure the number of accounts is equal to at exactly one element (with the use of check block) +check "account_check" { + data "snowflake_accounts" "assert_with_check_block" { + like = "account-name" + } + + assert { + condition = length(data.snowflake_accounts.assert_with_check_block.accounts) == 1 + error_message = "accounts filtered by '${data.snowflake_accounts.assert_with_check_block.like}' returned ${length(data.snowflake_accounts.assert_with_check_block.accounts)} accounts where one was expected" + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/account_show_output_ext.go b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/account_show_output_ext.go new file mode 100644 index 0000000000..41fa630c00 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/account_show_output_ext.go @@ -0,0 +1,112 @@ +package resourceshowoutputassert + +import ( + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" +) + +func AccountDatasourceShowOutput(t *testing.T, name string) *AccountShowOutputAssert { + t.Helper() + + a := AccountShowOutputAssert{ + ResourceAssert: assert.NewDatasourceAssert("data."+name, "show_output", "accounts.0."), + } + a.AddAssertion(assert.ValueSet("show_output.#", "1")) + return &a +} + +func (a *AccountShowOutputAssert) HasAccountUrlNotEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValuePresent("account_url")) + return a +} + +func (a *AccountShowOutputAssert) HasCreatedOnNotEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValuePresent("created_on")) + return a +} + +func (a *AccountShowOutputAssert) HasAccountLocatorNotEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValuePresent("account_locator")) + return a +} + +func (a *AccountShowOutputAssert) HasAccountLocatorUrlNotEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValuePresent("account_locator_url")) + return a +} + +func (a *AccountShowOutputAssert) HasConsumptionBillingEntityNameNotEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValuePresent("consumption_billing_entity_name")) + return a +} + +func (a *AccountShowOutputAssert) HasNoOrganizationOldUrl() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("organization_old_url")) + return a +} + +func (a *AccountShowOutputAssert) HasMarketplaceProviderBillingEntityNameNotEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValuePresent("marketplace_provider_billing_entity_name")) + return a +} + +func (a *AccountShowOutputAssert) HasNoAccountOldUrlSavedOn() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("account_old_url_saved_on")) + return a +} + +func (a *AccountShowOutputAssert) HasNoAccountOldUrlLastUsed() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("account_old_url_last_used")) + return a +} + +func (a *AccountShowOutputAssert) HasNoOrganizationOldUrlSavedOn() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("organization_old_url_saved_on")) + return a +} + +func (a *AccountShowOutputAssert) HasNoOrganizationOldUrlLastUsed() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("organization_old_url_last_used")) + return a +} + +func (a *AccountShowOutputAssert) HasNoDroppedOn() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("dropped_on")) + return a +} + +func (a *AccountShowOutputAssert) HasNoScheduledDeletionTime() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("scheduled_deletion_time")) + return a +} + +func (a *AccountShowOutputAssert) HasNoRestoredOn() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("restored_on")) + return a +} + +func (a *AccountShowOutputAssert) HasNoMovedToOrganization() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("moved_to_organization")) + return a +} + +func (a *AccountShowOutputAssert) HasMovedOnEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("moved_on")) + return a +} + +func (a *AccountShowOutputAssert) HasNoOrganizationUrlExpirationOn() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("organization_url_expiration_on")) + return a +} + +func (a *AccountShowOutputAssert) HasNoIsEventsAccount() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("is_events_account")) + return a +} + +func (a *AccountShowOutputAssert) HasNoIsOrganizationAccount() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueNotSet("is_organization_account")) + return a +} diff --git a/pkg/datasources/accounts.go b/pkg/datasources/accounts.go index d5aff6abec..c54f2920b6 100644 --- a/pkg/datasources/accounts.go +++ b/pkg/datasources/accounts.go @@ -2,168 +2,78 @@ package datasources import ( "context" - "log" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/datasources" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/snowflakeroles" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) var accountsSchema = map[string]*schema.Schema{ - "pattern": { - Type: schema.TypeString, + "with_history": { + Type: schema.TypeBool, Optional: true, - Description: "Specifies an account name pattern. If a pattern is specified, only accounts matching the pattern are returned.", + Description: "Includes dropped accounts that have not yet been deleted.", }, + "like": likeSchema, "accounts": { Type: schema.TypeList, Computed: true, - Description: "List of all the accounts available in the organization.", + Description: "Holds the aggregated output of all accounts details queries.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "organization_name": { - Type: schema.TypeString, + resources.ShowOutputAttributeName: { + Type: schema.TypeList, Computed: true, - Description: "Name of the organization.", - }, - "account_name": { - Type: schema.TypeString, - Computed: true, - Description: "User-defined name that identifies an account within the organization.", - }, - "region_group": { - Type: schema.TypeString, - Computed: true, - Description: "Region group where the account is located. Note: this column is only visible to organizations that span multiple Region Groups.", - }, - "snowflake_region": { - Type: schema.TypeString, - Computed: true, - Description: "Snowflake Region where the account is located. A Snowflake Region is a distinct location within a cloud platform region that is isolated from other Snowflake Regions. A Snowflake Region can be either multi-tenant or single-tenant (for a Virtual Private Snowflake account).", - }, - "edition": { - Type: schema.TypeString, - Computed: true, - Description: "Snowflake Edition of the account.", - }, - "account_url": { - Type: schema.TypeString, - Computed: true, - Description: "Preferred Snowflake access URL that includes the values of organization_name and account_name.", - }, - "created_on": { - Type: schema.TypeString, - Computed: true, - Description: "Date and time when the account was created.", - }, - "comment": { - Type: schema.TypeString, - Computed: true, - Description: "Comment for the account.", - }, - "account_locator": { - Type: schema.TypeString, - Computed: true, - Description: "System-assigned identifier of the acccount.", - }, - "account_locator_url": { - Type: schema.TypeString, - Computed: true, - Description: "Legacy Snowflake access URL syntax that includes the region_name and account_locator.", - }, - "managed_accounts": { - Type: schema.TypeInt, - Computed: true, - Description: "Indicates how many managed accounts have been created by the account.", - }, - "consumption_billing_entity_name": { - Type: schema.TypeString, - Computed: true, - Description: "Name of the consumption billing entity.", - }, - "marketplace_consumer_billing_entity_name": { - Type: schema.TypeString, - Computed: true, - Description: "Name of the marketplace consumer billing entity.", - }, - "marketplace_provider_billing_entity_name": { - Type: schema.TypeString, - Computed: true, - Description: "Name of the marketplace provider billing entity.", - }, - "old_account_url": { - Type: schema.TypeString, - Computed: true, - Description: "The previous account URL for a given account.", - }, - "is_org_admin": { - Type: schema.TypeBool, - Computed: true, - Description: "Indicates whether the ORGADMIN role is enabled in an account. If TRUE, the role is enabled.", + Description: "Holds the output of SHOW ACCOUNTS.", + Elem: &schema.Resource{ + Schema: schemas.ShowAccountSchema, + }, }, + // TODO(SNOW-1348092 - next prs): Add parameters }, }, }, } -// Accounts Snowflake Accounts resource. func Accounts() *schema.Resource { return &schema.Resource{ ReadContext: TrackingReadWrapper(datasources.Accounts, ReadAccounts), Schema: accountsSchema, + Description: "Data source used to get details of filtered accounts. Filtering is aligned with the current possibilities for [SHOW ACCOUNTS](https://docs.snowflake.com/en/sql-reference/sql/show-accounts) query. The results of SHOW are encapsulated in one output collection `accounts`.", } } -// ReadAccounts lists accounts. func ReadAccounts(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { client := meta.(*provider.Context).Client - ok, err := client.ContextFunctions.IsRoleInSession(ctx, snowflakeroles.Orgadmin) - if err != nil { - return diag.FromErr(err) - } - if !ok { - log.Printf("[DEBUG] ORGADMIN role is not in current session, cannot read accounts") - return nil - } - opts := &sdk.ShowAccountOptions{} - if pattern, ok := d.GetOk("pattern"); ok { - opts.Like = &sdk.Like{ - Pattern: sdk.String(pattern.(string)), - } + req := new(sdk.ShowAccountOptions) + handleLike(d, &req.Like) + if history, ok := d.GetOk("with_history"); ok && history.(bool) { + req.History = sdk.Bool(true) } - accounts, err := client.Accounts.Show(ctx, opts) + + accounts, err := client.Accounts.Show(ctx, req) if err != nil { return diag.FromErr(err) } d.SetId("accounts") - accountsFlatten := []map[string]interface{}{} - for _, account := range accounts { - m := map[string]interface{}{} - m["organization_name"] = account.OrganizationName - m["account_name"] = account.AccountName - m["region_group"] = account.RegionGroup - m["snowflake_region"] = account.SnowflakeRegion - m["edition"] = string(*account.Edition) - m["account_url"] = account.AccountURL - m["created_on"] = account.CreatedOn.String() - m["comment"] = account.Comment - m["account_locator"] = account.AccountLocator - m["account_locator_url"] = account.AccountLocatorURL - m["managed_accounts"] = account.ManagedAccounts - m["consumption_billing_entity_name"] = account.ConsumptionBillingEntityName - m["marketplace_consumer_billing_entity_name"] = account.MarketplaceConsumerBillingEntityName - m["marketplace_provider_billing_entity_name"] = account.MarketplaceProviderBillingEntityName - m["old_account_url"] = account.OldAccountURL - m["is_org_admin"] = account.IsOrgAdmin - accountsFlatten = append(accountsFlatten, m) + + flattenedAccounts := make([]map[string]any, len(accounts)) + for i, account := range accounts { + account := account + flattenedAccounts[i] = map[string]any{ + resources.ShowOutputAttributeName: []map[string]any{schemas.AccountToSchema(&account)}, + } } - if err := d.Set("accounts", accountsFlatten); err != nil { + + if err := d.Set("accounts", flattenedAccounts); err != nil { return diag.FromErr(err) } + return nil } diff --git a/pkg/datasources/accounts_acceptance_test.go b/pkg/datasources/accounts_acceptance_test.go index ddefbd768f..707778fcab 100644 --- a/pkg/datasources/accounts_acceptance_test.go +++ b/pkg/datasources/accounts_acceptance_test.go @@ -1,35 +1,101 @@ package datasources_test import ( + "fmt" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) -func TestAcc_Accounts(t *testing.T) { - t.Skipf("Skipping because of: ORGADMIN role is not in current session, cannot read accounts") +func TestAcc_Accounts_Complete(t *testing.T) { + _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) + _ = testenvs.GetOrSkipTest(t, testenvs.TestAccountCreate) + + prefix := acc.TestClient().Ids.AlphaN(4) + + privateKey := random.GenerateRSAPrivateKey(t) + publicKey, _ := random.GenerateRSAPublicKeyFromPrivateKey(t, privateKey) + account, accountCleanup := acc.TestClient().Account.CreateWithRequest(t, acc.TestClient().Ids.RandomAccountObjectIdentifierWithPrefix(prefix), &sdk.CreateAccountOptions{ + AdminName: acc.TestClient().Ids.Alpha(), + AdminRSAPublicKey: &publicKey, + AdminUserType: sdk.Pointer(sdk.UserTypeService), + Email: "test@example.com", + Edition: sdk.EditionStandard, + }) + t.Cleanup(accountCleanup) + + _, account2Cleanup := acc.TestClient().Account.CreateWithRequest(t, acc.TestClient().Ids.RandomAccountObjectIdentifierWithPrefix(prefix), &sdk.CreateAccountOptions{ + AdminName: acc.TestClient().Ids.Alpha(), + AdminRSAPublicKey: &publicKey, + AdminUserType: sdk.Pointer(sdk.UserTypeService), + Email: "test@example.com", + Edition: sdk.EditionStandard, + }) + t.Cleanup(account2Cleanup) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, - PreCheck: func() { acc.TestAccPreCheck(t) }, TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.RequireAbove(tfversion.Version1_5_0), }, - CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: accountsConfig(), + Config: accountsConfig(prefix + "%"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.snowflake_accounts.accounts", "accounts.#"), + resource.TestCheckResourceAttr("data.snowflake_accounts.test", "accounts.#", "2"), + ), + }, + { + Config: accountsConfig(account.ID().Name()), + Check: assert.AssertThat(t, + assert.Check(resource.TestCheckResourceAttr("data.snowflake_accounts.test", "accounts.#", "1")), + resourceshowoutputassert.AccountDatasourceShowOutput(t, "snowflake_accounts.test"). + HasOrganizationName(account.OrganizationName). + HasAccountName(account.AccountName). + HasSnowflakeRegion(account.SnowflakeRegion). + HasRegionGroup(""). + HasEdition(sdk.EditionStandard). + HasAccountUrlNotEmpty(). + HasCreatedOnNotEmpty(). + HasComment("SNOWFLAKE"). + HasAccountLocatorNotEmpty(). + HasAccountLocatorUrlNotEmpty(). + HasManagedAccounts(0). + HasConsumptionBillingEntityNameNotEmpty(). + HasMarketplaceConsumerBillingEntityName(""). + HasMarketplaceProviderBillingEntityNameNotEmpty(). + HasOldAccountURL(""). + HasIsOrgAdmin(false). + HasNoAccountOldUrlSavedOn(). + HasNoAccountOldUrlLastUsed(). + HasNoOrganizationOldUrl(). + HasNoOrganizationOldUrlSavedOn(). + HasNoOrganizationOldUrlLastUsed(). + HasNoIsEventsAccount(). + HasNoIsOrganizationAccount(). + HasNoDroppedOn(). + HasNoScheduledDeletionTime(). + HasNoRestoredOn(). + HasNoMovedToOrganization(). + HasMovedOnEmpty(). + HasNoOrganizationUrlExpirationOn(), ), }, }, }) } -func accountsConfig() string { - return `data "snowflake_accounts" "accounts" {}` +func accountsConfig(pattern string) string { + return fmt.Sprintf(`data "snowflake_accounts" "test" { + with_history = true + like = "%s" +}`, pattern) } From f3d4c35341d92ecd239d1718a5cce3a0e7e8f225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Cie=C5=9Blak?= Date: Wed, 11 Dec 2024 13:19:25 +0100 Subject: [PATCH 2/2] test fix --- docs/data-sources/accounts.md | 13 ++++ .../account_show_output_ext.go | 62 ++++++++++++++++++- pkg/datasources/accounts_acceptance_test.go | 24 +++---- 3 files changed, 86 insertions(+), 13 deletions(-) diff --git a/docs/data-sources/accounts.md b/docs/data-sources/accounts.md index 3d7728649c..f378741edd 100644 --- a/docs/data-sources/accounts.md +++ b/docs/data-sources/accounts.md @@ -90,16 +90,29 @@ Read-Only: - `account_locator` (String) - `account_locator_url` (String) - `account_name` (String) +- `account_old_url_last_used` (String) +- `account_old_url_saved_on` (String) - `account_url` (String) - `comment` (String) - `consumption_billing_entity_name` (String) - `created_on` (String) +- `dropped_on` (String) - `edition` (String) +- `is_events_account` (Boolean) - `is_org_admin` (Boolean) +- `is_organization_account` (Boolean) - `managed_accounts` (Number) - `marketplace_consumer_billing_entity_name` (String) - `marketplace_provider_billing_entity_name` (String) +- `moved_on` (String) +- `moved_to_organization` (String) - `old_account_url` (String) - `organization_name` (String) +- `organization_old_url` (String) +- `organization_old_url_last_used` (String) +- `organization_old_url_saved_on` (String) +- `organization_url_expiration_on` (String) - `region_group` (String) +- `restored_on` (String) +- `scheduled_deletion_time` (String) - `snowflake_region` (String) diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/account_show_output_ext.go b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/account_show_output_ext.go index 41fa630c00..82f9d25bbc 100644 --- a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/account_show_output_ext.go +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/account_show_output_ext.go @@ -46,6 +46,11 @@ func (a *AccountShowOutputAssert) HasNoOrganizationOldUrl() *AccountShowOutputAs return a } +func (a *AccountShowOutputAssert) HasOrganizationOldUrlEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("organization_old_url", "")) + return a +} + func (a *AccountShowOutputAssert) HasMarketplaceProviderBillingEntityNameNotEmpty() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValuePresent("marketplace_provider_billing_entity_name")) return a @@ -56,43 +61,83 @@ func (a *AccountShowOutputAssert) HasNoAccountOldUrlSavedOn() *AccountShowOutput return a } +func (a *AccountShowOutputAssert) HasAccountOldUrlSavedOnEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("account_old_url_saved_on", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoAccountOldUrlLastUsed() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("account_old_url_last_used")) return a } +func (a *AccountShowOutputAssert) HasAccountOldUrlLastUsedEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("account_old_url_last_used", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoOrganizationOldUrlSavedOn() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("organization_old_url_saved_on")) return a } +func (a *AccountShowOutputAssert) HasOrganizationOldUrlSavedOnEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("organization_old_url_saved_on", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoOrganizationOldUrlLastUsed() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("organization_old_url_last_used")) return a } +func (a *AccountShowOutputAssert) HasOrganizationOldUrlLastUsedEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("organization_old_url_last_used", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoDroppedOn() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("dropped_on")) return a } +func (a *AccountShowOutputAssert) HasDroppedOnEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("dropped_on", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoScheduledDeletionTime() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("scheduled_deletion_time")) return a } +func (a *AccountShowOutputAssert) HasScheduledDeletionTimeEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("scheduled_deletion_time", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoRestoredOn() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("restored_on")) return a } +func (a *AccountShowOutputAssert) HasRestoredOnEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("restored_on", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoMovedToOrganization() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("moved_to_organization")) return a } +func (a *AccountShowOutputAssert) HasMovedToOrganizationEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("moved_to_organization", "")) + return a +} + func (a *AccountShowOutputAssert) HasMovedOnEmpty() *AccountShowOutputAssert { - a.AddAssertion(assert.ResourceShowOutputValueNotSet("moved_on")) + a.AddAssertion(assert.ResourceShowOutputValueSet("moved_on", "")) return a } @@ -101,12 +146,27 @@ func (a *AccountShowOutputAssert) HasNoOrganizationUrlExpirationOn() *AccountSho return a } +func (a *AccountShowOutputAssert) HasOrganizationUrlExpirationOnEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("organization_url_expiration_on", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoIsEventsAccount() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("is_events_account")) return a } +func (a *AccountShowOutputAssert) HasIsEventsAccountEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("is_events_account", "")) + return a +} + func (a *AccountShowOutputAssert) HasNoIsOrganizationAccount() *AccountShowOutputAssert { a.AddAssertion(assert.ResourceShowOutputValueNotSet("is_organization_account")) return a } + +func (a *AccountShowOutputAssert) HasIsOrganizationAccountEmpty() *AccountShowOutputAssert { + a.AddAssertion(assert.ResourceShowOutputValueSet("is_organization_account", "")) + return a +} diff --git a/pkg/datasources/accounts_acceptance_test.go b/pkg/datasources/accounts_acceptance_test.go index 707778fcab..75df1fed2c 100644 --- a/pkg/datasources/accounts_acceptance_test.go +++ b/pkg/datasources/accounts_acceptance_test.go @@ -74,19 +74,19 @@ func TestAcc_Accounts_Complete(t *testing.T) { HasMarketplaceProviderBillingEntityNameNotEmpty(). HasOldAccountURL(""). HasIsOrgAdmin(false). - HasNoAccountOldUrlSavedOn(). - HasNoAccountOldUrlLastUsed(). - HasNoOrganizationOldUrl(). - HasNoOrganizationOldUrlSavedOn(). - HasNoOrganizationOldUrlLastUsed(). - HasNoIsEventsAccount(). - HasNoIsOrganizationAccount(). - HasNoDroppedOn(). - HasNoScheduledDeletionTime(). - HasNoRestoredOn(). - HasNoMovedToOrganization(). + HasAccountOldUrlSavedOnEmpty(). + HasAccountOldUrlLastUsedEmpty(). + HasOrganizationOldUrlEmpty(). + HasOrganizationOldUrlSavedOnEmpty(). + HasOrganizationOldUrlLastUsedEmpty(). + HasIsEventsAccount(false). + HasIsOrganizationAccount(false). + HasDroppedOnEmpty(). + HasScheduledDeletionTimeEmpty(). + HasRestoredOnEmpty(). + HasMovedToOrganizationEmpty(). HasMovedOnEmpty(). - HasNoOrganizationUrlExpirationOn(), + HasOrganizationUrlExpirationOnEmpty(), ), }, },