Skip to content

Commit

Permalink
Fix review
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>
  • Loading branch information
pierre-emmanuelJ committed Dec 23, 2019
1 parent eda1f58 commit 48770c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
12 changes: 6 additions & 6 deletions exoscale/datasource_exoscale_compute_ipaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func datasourceComputeIPAddress() *schema.Resource {
},
"description": {
Type: schema.TypeString,
Description: "Description of the IP",
Description: "Description of the Elastic IP",
Optional: true,
ConflictsWith: []string{"ip_address", "id", "tags"},
},
Expand All @@ -31,7 +31,7 @@ func datasourceComputeIPAddress() *schema.Resource {
},
"id": {
Type: schema.TypeString,
Description: "ID of the IP Address",
Description: "ID of the Elastic IP",
Optional: true,
ConflictsWith: []string{"description", "ip_address", "tags"},
},
Expand Down Expand Up @@ -82,13 +82,13 @@ func datasourceComputeIPAddressRead(d *schema.ResourceData, meta interface{}) er

ips := resp.(*egoscale.ListPublicIPAddressesResponse).PublicIPAddress

t, ok := d.GetOk("tags")
t, byTags := d.GetOk("tags")
switch {
case d.Get("id").(string) != "":
return datasourceComputeIPAddressApply(d, ips)
case d.Get("ip_address").(string) != "":
return datasourceComputeIPAddressApply(d, ips)
case ok:
case byTags:
ipAddrs := make([]egoscale.IPAddress, 0)
for _, ip := range ips {
if compareTags(ip, t.(map[string]interface{})) {
Expand All @@ -113,9 +113,9 @@ func datasourceComputeIPAddressApply(d *schema.ResourceData, ipAddresses []egosc
len := len(ipAddresses)
switch {
case len == 0:
return fmt.Errorf("No IP Address found")
return fmt.Errorf("No matching Elastic IP found")
case len > 1:
return fmt.Errorf("More than one IP Address found")
return fmt.Errorf("More than one Elastic IPs found")
}
ip := ipAddresses[0]
d.SetId(ip.ID.String())
Expand Down
6 changes: 2 additions & 4 deletions exoscale/datasource_exoscale_compute_ipaddress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ func TestAccDatasourceComputeIPAddress(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
%s
Config: `
data "exoscale_compute_ipaddress" "ip_address" {
zone = "ch-gva-2"
}`, testAccIPAddressConfigCreate),
}`,
ExpectError: regexp.MustCompile(`You must set at least one attribute "id", "ip_address", "tags" or "description"`),
},
{
Expand Down

0 comments on commit 48770c7

Please sign in to comment.