-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add data source enterprise project support (#620)
- Loading branch information
1 parent
5db4cc1
commit 8aadf2d
Showing
10 changed files
with
270 additions
and
0 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,51 @@ | ||
--- | ||
subcategory: "Enterprise Project Management Service (EPS)" | ||
--- | ||
|
||
# huaweicloud\_enterprise\_project | ||
|
||
Use this data source to get an enterprise project from HuaweiCloud | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "huaweicloud_enterprise_project" "test" { | ||
name = "test" | ||
} | ||
``` | ||
|
||
## Resources Supported Currently: | ||
Service Name | Resource Name | ||
---- | --- | ||
VPC | huaweicloud_vpc<br>huaweicloud_vpc_eip<br>huaweicloud_vpc_bandwidth<br>huaweicloud_networking_secgroup | ||
ECS | huaweicloud_compute_instance | ||
CCE | huaweicloud_cce_cluster | ||
RDS | huaweicloud_rds_instance | ||
OBS | hauweicloud_obs_bucket | ||
SFS | hauweicloud_sfs_file_system | ||
DCS | huaweicloud_dcs_instance | ||
NAT | huaweicloud_nat_gateway | ||
CDM | huaweicloud_cdm_cluster | ||
CDN | huaweicloud_cdn_domain | ||
GaussDB | huaweicloud_gaussdb_cassandra_instance<br>huaweicloud_gaussdb_mysql_instance<br>huaweicloud_gaussdb_opengauss_instance | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Optional) Specifies the enterprise project name. Fuzzy search is supported. | ||
|
||
* `id` - (Optional) Specifies the ID of an enterprise project. The value 0 indicates enterprise project default. | ||
|
||
* `status` - (Optional) Specifies the status of an enterprise project. | ||
- 1 indicates Enabled. | ||
- 2 indicates Disabled. | ||
|
||
## Attributes Reference | ||
|
||
All above argument parameters can be exported as attribute parameters along with attribute reference: | ||
|
||
* `description` - Provides supplementary information about the enterprise project. | ||
|
||
* `created_at` - Specifies the time (UTC) when the enterprise project was created. Example: 2018-05-18T06:49:06Z | ||
|
||
* `updated_at` - Specifies the time (UTC) when the enterprise project was modified. Example: 2018-05-28T02:21:36Z | ||
|
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
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,84 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/eps/v1/enterpriseprojects" | ||
) | ||
|
||
func DataSourceEnterpriseProject() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceEnterpriseProjectRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"updated_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceEnterpriseProjectRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
region := GetRegion(d, config) | ||
epsClient, err := config.EnterpriseProjectClient(region) | ||
if err != nil { | ||
return fmt.Errorf("Error creating Huaweicloud eps client %s", err) | ||
} | ||
|
||
listOpts := enterpriseprojects.ListOpts{ | ||
Name: d.Get("name").(string), | ||
ID: d.Get("id").(string), | ||
Status: d.Get("status").(int), | ||
} | ||
projects, err := enterpriseprojects.List(epsClient, listOpts).Extract() | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error retriving enterprise projects %s", err) | ||
} | ||
|
||
if len(projects) < 1 { | ||
return fmt.Errorf("Your query returned no results. " + | ||
"Please change your search criteria and try again.") | ||
} | ||
|
||
if len(projects) > 1 { | ||
return fmt.Errorf("Your query returned more than one result." + | ||
" Please try a more specific search criteria") | ||
} | ||
|
||
project := projects[0] | ||
|
||
d.SetId(project.ID) | ||
d.Set("name", project.Name) | ||
d.Set("description", project.Description) | ||
d.Set("status", project.Status) | ||
d.Set("created_at", project.CreatedAt) | ||
d.Set("updated_at", project.UpdatedAt) | ||
|
||
return nil | ||
} |
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,49 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
func TestAccEnterpriseProjectDataSource_basic(t *testing.T) { | ||
resourceName := "data.huaweicloud_enterprise_project.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccEnterpriseProjectDataSource_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckEnterpriseProjectDataSourceID(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "name", "default"), | ||
resource.TestCheckResourceAttr(resourceName, "id", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckEnterpriseProjectDataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find enterprise project data source: %s ", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("enterprise project data source ID not set ") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccEnterpriseProjectDataSource_basic = ` | ||
data "huaweicloud_enterprise_project" "test" { | ||
name = "default" | ||
} | ||
` |
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
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
34 changes: 34 additions & 0 deletions
34
vendor/github.com/huaweicloud/golangsdk/openstack/eps/v1/enterpriseprojects/requests.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
vendor/github.com/huaweicloud/golangsdk/openstack/eps/v1/enterpriseprojects/results.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
vendor/github.com/huaweicloud/golangsdk/openstack/eps/v1/enterpriseprojects/urls.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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