-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(IAM): import IAM resource, unit test and document. (#1044)
- Loading branch information
1 parent
9f756c2
commit f6b7aad
Showing
5 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
46 changes: 46 additions & 0 deletions
46
flexibleengine/acceptance/data_source_flexibleengine_account_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" {} | ||
` |
63 changes: 63 additions & 0 deletions
63
flexibleengine/acceptance/data_source_flexibleengine_identity_projects_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters