From 388384d443df656a00a2a6c766303198f2a0e8cc Mon Sep 17 00:00:00 2001 From: Zippo-Wang <852420284@qq.com> Date: Fri, 13 Oct 2023 11:32:40 +0800 Subject: [PATCH] feat(IAM): import IAM resource, unit test and document. --- docs/data-sources/account.md | 25 ++++++++++ ...data_source_flexibleengine_account_test.go | 46 +++++++++++++++++++ flexibleengine/provider.go | 1 + 3 files changed, 72 insertions(+) create mode 100644 docs/data-sources/account.md create mode 100644 flexibleengine/acceptance/data_source_flexibleengine_account_test.go diff --git a/docs/data-sources/account.md b/docs/data-sources/account.md new file mode 100644 index 00000000..3b1d155c --- /dev/null +++ b/docs/data-sources/account.md @@ -0,0 +1,25 @@ +# flexibleengine_account + +Use this data source to get information about the current account. + +## Example Usage + +```hcl +data "flexibleengine_account" "current" {} + +output "current_account_id" { + value = data.flexibleengine_account.current.id +} +``` + +## Argument Reference + +There are no arguments available for this data source. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The account ID. + +* `name` - The account name. diff --git a/flexibleengine/acceptance/data_source_flexibleengine_account_test.go b/flexibleengine/acceptance/data_source_flexibleengine_account_test.go new file mode 100644 index 00000000..02997836 --- /dev/null +++ b/flexibleengine/acceptance/data_source_flexibleengine_account_test.go @@ -0,0 +1,46 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccDatasourceAccount_basic(t *testing.T) { + rName := "data.flexibleengine_account.current" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDatasourceAccount_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckAccountDataSourceID(rName), + resource.TestCheckResourceAttrSet(rName, "name"), + ), + }, + }, + }) +} + +func testAccCheckAccountDataSourceID(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Can't find the account data source: %s ", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("the account data source ID not set") + } + + return nil + } +} + +const testAccDatasourceAccount_basic = ` +data "flexibleengine_account" "current" {} +` diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 7b666ee5..c9116508 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -308,6 +308,7 @@ func Provider() *schema.Provider { "flexibleengine_images_images": ims.DataSourceImagesImages(), "flexibleengine_networking_port": vpc.DataSourceNetworkingPortV2(), + "flexibleengine_account": huaweicloud.DataSourceAccount(), "flexibleengine_identity_group": iam.DataSourceIdentityGroup(), "flexibleengine_identity_users": iam.DataSourceIdentityUsers(), "flexibleengine_sfs_turbos": sfs.DataSourceTurbos(),