Skip to content

Commit

Permalink
Allow network datasource query by ID/label/region (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
zulh-civo committed Sep 6, 2021
1 parent 0bbeab8 commit 37e3d50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions civo/datasource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ func dataSourceNetwork() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.NoZeroValues,
ExactlyOneOf: []string{"id", "label", "region"},
AtLeastOneOf: []string{"id", "label", "region"},
},
"label": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.NoZeroValues,
ExactlyOneOf: []string{"id", "label", "region"},
AtLeastOneOf: []string{"id", "label", "region"},
},
"region": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.NoZeroValues,
AtLeastOneOf: []string{"id", "label", "region"},
},
// Computed resource
"name": {
Expand Down
5 changes: 4 additions & 1 deletion civo/resource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ func resourceVolumeCreate(d *schema.ResourceData, m interface{}) error {
Name: d.Get("name").(string),
SizeGigabytes: d.Get("size_gb").(int),
NetworkID: d.Get("network_id").(string),

// if "region" is set at provider level, use it
Region: apiClient.Region,
}

// overwrite the region if is define in the datasource
// if "region" is set in configuration file, use it
if region, ok := d.GetOk("region"); ok {
currentRegion := region.(string)
apiClient.Region = currentRegion
Expand Down

0 comments on commit 37e3d50

Please sign in to comment.