Skip to content

Commit d131aa1

Browse files
data: get vpc in project by project name (#209)
1 parent b4e5d6f commit d131aa1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cloudstack/data_source_cloudstack_vpc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func dataSourceCloudstackVPC() *schema.Resource {
6666
"project": {
6767
Type: schema.TypeString,
6868
Computed: true,
69+
Optional: true,
6970
},
7071

7172
"zone_name": {
@@ -81,6 +82,12 @@ func dataSourceCloudstackVPC() *schema.Resource {
8182
func datasourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
8283
cs := meta.(*cloudstack.CloudStackClient)
8384
p := cs.VPC.NewListVPCsParams()
85+
86+
// If there is a project supplied, we retrieve and set the project id
87+
if err := setProjectid(p, cs, d); err != nil {
88+
return err
89+
}
90+
8491
csVPCs, err := cs.VPC.ListVPCs(p)
8592

8693
if err != nil {

website/docs/d/vpc.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Use this datasource to get information about a vpc for use in other resources.
1414

1515
```hcl
1616
data "cloudstack_vpc" "vpc-data-source"{
17+
project = "project-1"
1718
filter{
1819
name = "name"
1920
value= "test-vpc"
@@ -27,6 +28,7 @@ data "cloudstack_vpc" "vpc-data-source"{
2728
### Argument Reference
2829

2930
* `filter` - (Required) One or more name/value pairs to filter off of. You can apply filters on any exported attributes.
31+
* `project` - (Optional) The name or ID of the project the vpc belongs to.
3032

3133
## Attributes Reference
3234

@@ -38,4 +40,4 @@ The following attributes are exported:
3840
* `vpc_offering_name` - Vpc offering name the VPC is created from.
3941
* `network_domain` - The network domain of the VPC.
4042
* `project` - The project name of the VPC.
41-
* `zone_name` - The name of the zone the VPC belongs to.
43+
* `zone_name` - The name of the zone the VPC belongs to.

0 commit comments

Comments
 (0)