Skip to content

feat(IAM): import IAM resource, unit test and document. #1044

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

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
50 changes: 50 additions & 0 deletions docs/data-sources/identity_projects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
subcategory: "Identity and Access Management (IAM)"
---

# flexibleengine_identity_projects

Use this data source to query the IAM project list within FlexibleEngine.

-> **NOTE:** You *must* have IAM read privileges to use this data source.

## Example Usage

### Obtain project information by name

```hcl
data "flexibleengine_identity_projects" "test" {
name = "eu-west-0_demo"
}
```

### Obtain special project information by name

```hcl
data "flexibleengine_identity_projects" "test" {
name = "MOS" // The project for OBS Billing
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Optional, String) Specifies the IAM project name to query.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The data source ID.

* `projects` - The details of the query projects. The [projects](#iam_projects) object structure is documented below.

<a name="iam_projects"></a>
The `projects` block supports:

* `id` - The IAM project ID.

* `name` - The IAM project name.

* `enabled` - Whether the IAM project is enabled.
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" {}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package acceptance

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccIdentityProjectsDataSource_basic(t *testing.T) {
dataSourceName := "data.flexibleengine_identity_projects.test"
dc := acceptance.InitDataSourceCheck(dataSourceName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccIdentityProjectsDataSource_basic,
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSourceName, "projects.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "projects.0.name", "MOS"),
resource.TestCheckResourceAttr(dataSourceName, "projects.0.enabled", "true"),
),
},
},
})
}

func TestAccIdentityProjectsDataSource_subProject(t *testing.T) {
dataSourceName := "data.flexibleengine_identity_projects.test"
dc := acceptance.InitDataSourceCheck(dataSourceName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccIdentityProjectsDataSource_subProject,
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSourceName, "projects.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "projects.0.name", "eu-west-0_test"),
resource.TestCheckResourceAttr(dataSourceName, "projects.0.enabled", "true"),
),
},
},
})
}

const testAccIdentityProjectsDataSource_basic string = `
data "flexibleengine_identity_projects" "test" {
name = "MOS"
}
`

const testAccIdentityProjectsDataSource_subProject string = `
data "flexibleengine_identity_projects" "test" {
name = "eu-west-0_test"
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func testAccCheckObsBucketObjectExists(n string) resource.TestCheckFunc {
}
}


func testAccCheckObsObjectDataSourceExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
7 changes: 5 additions & 2 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,11 @@ func Provider() *schema.Provider {
"flexibleengine_images_images": ims.DataSourceImagesImages(),

"flexibleengine_networking_port": vpc.DataSourceNetworkingPortV2(),
"flexibleengine_identity_group": iam.DataSourceIdentityGroup(),
"flexibleengine_identity_users": iam.DataSourceIdentityUsers(),

"flexibleengine_account": huaweicloud.DataSourceAccount(),
"flexibleengine_identity_group": iam.DataSourceIdentityGroup(),
"flexibleengine_identity_projects": iam.DataSourceIdentityProjects(),
"flexibleengine_identity_users": iam.DataSourceIdentityUsers(),

"flexibleengine_rds_backups": rds.DataSourceBackup(),
"flexibleengine_rds_engine_versions": rds.DataSourceRdsEngineVersionsV3(),
Expand Down