Skip to content

Commit

Permalink
feat(IAM): import IAM resource, unit test and document.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zippo-Wang committed Oct 13, 2023
1 parent f1b8d5f commit 388384d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/data-sources/account.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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" {}
`
1 change: 1 addition & 0 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 388384d

Please sign in to comment.