Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Cyvoct <[email protected]>
  • Loading branch information
Sh4d1 committed Apr 15, 2020
1 parent fce01e9 commit 760e5a3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
16 changes: 11 additions & 5 deletions scaleway/resource_lb_beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func resourceScalewayLbBeta() *schema.Resource {
Optional: true,
Description: "Array of tags to associate with the load-balancer",
},
"keep_ip_on_delete": {
"release_ip_on_deletion": {
Type: schema.TypeBool,
Computed: true,
},
Expand Down Expand Up @@ -73,11 +73,11 @@ func resourceScalewayLbBetaCreate(d *schema.ResourceData, m interface{}) error {
Type: d.Get("type").(string),
}

if ipID, ok := d.GetOk("ip_id"); ok {
if ipID, ok := d.GetOkExists("ip_id"); ok {
createReq.IPID = scw.StringPtr(expandID(ipID.(string)))
_ = d.Set("keep_ip_on_delete", true)
_ = d.Set("release_ip_on_deletion", false)
} else {
_ = d.Set("keep_ip_on_delete", false)
_ = d.Set("release_ip_on_deletion", true)
}

if raw, ok := d.GetOk("tags"); ok {
Expand Down Expand Up @@ -123,6 +123,12 @@ func resourceScalewayLbBetaRead(d *schema.ResourceData, m interface{}) error {
return err
}

if _, ok := d.GetOkExists("ip_id"); ok {
_ = d.Set("release_ip_on_deletion", false)
} else {
_ = d.Set("release_ip_on_deletion", true)
}

_ = d.Set("name", res.Name)
_ = d.Set("region", string(region))
_ = d.Set("organization_id", res.OrganizationID)
Expand Down Expand Up @@ -168,7 +174,7 @@ func resourceScalewayLbBetaDelete(d *schema.ResourceData, m interface{}) error {
Region: region,
LbID: ID,
// This parameter will probably be breaking change when ip pre reservation will exist.
ReleaseIP: !d.Get("keep_ip_on_delete").(bool),
ReleaseIP: d.Get("release_ip_on_deletion").(bool),
})

if err != nil && !is404Error(err) {
Expand Down
45 changes: 45 additions & 0 deletions scaleway/resource_lb_beta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestAccScalewayLbAndIPBeta(t *testing.T) {
testCheckResourceAttrUUID("scaleway_lb_beta.lb01", "ip_id"),
testCheckResourceAttrIPv4("scaleway_lb_beta.lb01", "ip_address"),
resource.TestCheckResourceAttrPair("scaleway_lb_beta.lb01", "ip_id", "scaleway_lb_ip_beta.ip01", "id"),
resource.TestCheckResourceAttr("scaleway_lb_beta.lb01", "release_ip_on_deletion", "false"),
),
},
{
Expand All @@ -125,6 +126,50 @@ func TestAccScalewayLbAndIPBeta(t *testing.T) {
})
}

func TestAccScalewayLbThenIPBeta(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewayLbBetaDestroy,
Steps: []resource.TestStep{
{
Config: `
resource scaleway_lb_beta lb01 {
name = "test-lb"
type = "lb-s"
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayLbBetaExists("scaleway_lb_beta.lb01"),
resource.TestCheckResourceAttr("scaleway_lb_beta.lb01", "name", "test-lb"),
testCheckResourceAttrUUID("scaleway_lb_beta.lb01", "ip_id"),
testCheckResourceAttrIPv4("scaleway_lb_beta.lb01", "ip_address"),
resource.TestCheckResourceAttr("scaleway_lb_beta.lb01", "release_ip_on_deletion", "true"),
),
},
{
Config: `
resource scaleway_lb_ip_beta ip01 {
}
resource scaleway_lb_beta lb01 {
ip_id = scaleway_lb_ip_beta.ip01.id
name = "test-lb"
type = "lb-s"
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayLbBetaExists("scaleway_lb_beta.lb01"),
testAccCheckScalewayLbIPBetaExists("scaleway_lb_ip_beta.ip01"),
resource.TestCheckResourceAttrPair("scaleway_lb_beta.lb01", "ip_id", "scaleway_lb_ip_beta.ip01", "id"),
resource.TestCheckResourceAttr("scaleway_lb_beta.lb01", "release_ip_on_deletion", "false"),
resource.TestCheckResourceAttrPair("scaleway_lb_beta.lb01", "ip_id", "scaleway_lb_ip_beta.ip01", "id"),
),
},
},
})
}

func testAccCheckScalewayLbBetaExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down

0 comments on commit 760e5a3

Please sign in to comment.