Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Mar 14, 2024
1 parent 56a5ba7 commit 0e0d5bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
2 changes: 0 additions & 2 deletions outscale/data_source_outscale_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ func buildOutscaleOAPIDataSourceSecurityGroupFilters(set *schema.Set) oscgo.Filt
}

switch name := m["name"].(string); name {
case "account_ids":
filters.SetAccountIds(filterValues)
case "descriptions":
filters.SetDescriptions(filterValues)
case "inbound_rule_account_ids":
Expand Down
26 changes: 6 additions & 20 deletions outscale/resource_outscale_route_table_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"errors"
"fmt"
"log"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -57,16 +55,13 @@ func resourceOutscaleOAPILinkRouteTable() *schema.Resource {

func resourceOutscaleOAPILinkRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*OutscaleClient).OSCAPI
subnetID := d.Get("subnet_id").(string)
routeTableID := d.Get("route_table_id").(string)
log.Printf("[INFO] Creating route table link: %s => %s", subnetID, routeTableID)
linkRouteTableOpts := oscgo.LinkRouteTableRequest{
RouteTableId: routeTableID,
SubnetId: subnetID,
}

var resp oscgo.LinkRouteTableResponse
var err error

linkRouteTableOpts := oscgo.LinkRouteTableRequest{
RouteTableId: d.Get("route_table_id").(string),
SubnetId: d.Get("subnet_id").(string),
}
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
rp, httpResp, err := conn.RouteTableApi.LinkRouteTable(context.Background()).LinkRouteTableRequest(linkRouteTableOpts).Execute()
Expand Down Expand Up @@ -120,25 +115,16 @@ func resourceOutscaleOAPILinkRouteTableRead(d *schema.ResourceData, meta interfa
func resourceOutscaleOAPILinkRouteTableDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*OutscaleClient).OSCAPI

log.Printf("[INFO] Deleting link route table: %s", d.Id())

var err error
var statusCode int
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, httpResp, err := conn.RouteTableApi.UnlinkRouteTable(context.Background()).UnlinkRouteTableRequest(oscgo.UnlinkRouteTableRequest{
LinkRouteTableId: d.Id(),
}).Execute()
if err != nil {
return utils.CheckThrottling(httpResp, err)
}
statusCode = httpResp.StatusCode
return nil
})

if err != nil {
if statusCode == http.StatusNotFound {
return nil
}
return fmt.Errorf("Error deleting link route table: %s", err)
}

Expand Down
8 changes: 4 additions & 4 deletions outscale/resource_outscale_route_table_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ const testAccOAPILinkRouteTableConfig = `
}
resource "outscale_subnet" "foo" {
net_id = "${outscale_net.foo.id}"
net_id = outscale_net.foo.id
ip_range = "10.1.1.0/24"
}
resource "outscale_route_table" "foo" {
net_id = "${outscale_net.foo.id}"
net_id = outscale_net.foo.id
}
resource "outscale_route_table_link" "foo" {
route_table_id = "${outscale_route_table.foo.id}"
subnet_id = "${outscale_subnet.foo.id}"
route_table_id = outscale_route_table.foo.id
subnet_id = outscale_subnet.foo.id
}
`

0 comments on commit 0e0d5bc

Please sign in to comment.