Skip to content

Commit

Permalink
Support lb type param on terraform sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
asaha2 committed Aug 29, 2023
1 parent 364fc6c commit 77a29c7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions digitalocean/loadbalancer/datasource_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ func DataSourceDigitalOceanLoadbalancer() *schema.Resource {
},
},
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "the type of the load balancer (GLOBAL or REGIONAL)",
},
},
}
}
Expand Down Expand Up @@ -323,6 +328,7 @@ func dataSourceDigitalOceanLoadbalancerRead(ctx context.Context, d *schema.Resou
d.Set("vpc_uuid", foundLoadbalancer.VPCUUID)
d.Set("http_idle_timeout_seconds", foundLoadbalancer.HTTPIdleTimeoutSeconds)
d.Set("project_id", foundLoadbalancer.ProjectID)
d.Set("type", foundLoadbalancer.Type)

if err := d.Set("droplet_ids", flattenDropletIds(foundLoadbalancer.DropletIDs)); err != nil {
return diag.Errorf("[DEBUG] Error setting Load Balancer droplet_ids - error: %#v", err)
Expand Down
9 changes: 9 additions & 0 deletions digitalocean/loadbalancer/datasource_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ data "digitalocean_loadbalancer" "foobar" {
"data.digitalocean_loadbalancer.foobar", "region", "nyc3"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "size_unit", "1"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "type", "REGIONAL"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(
Expand Down Expand Up @@ -109,6 +111,8 @@ data "digitalocean_loadbalancer" "foobar" {
"data.digitalocean_loadbalancer.foobar", "region", "nyc3"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "size_unit", "1"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "type", "REGIONAL"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(
Expand Down Expand Up @@ -173,6 +177,8 @@ data "digitalocean_loadbalancer" "foobar" {
"data.digitalocean_loadbalancer.foobar", "region", "nyc3"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "size_unit", "6"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "type", "REGIONAL"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(
Expand Down Expand Up @@ -235,6 +241,8 @@ data "digitalocean_loadbalancer" "foobar" {
"data.digitalocean_loadbalancer.foobar", "region", "nyc3"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "size_unit", "6"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "type", "REGIONAL"),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(
Expand Down Expand Up @@ -663,6 +671,7 @@ resource "digitalocean_loadbalancer" "foo" {
name = "%s"
region = "nyc3"
size = "%s"
type = "REGIONAL"
forwarding_rule {
entry_port = 80
Expand Down
6 changes: 5 additions & 1 deletion digitalocean/loadbalancer/resource_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ func buildLoadBalancerRequest(client *godo.Client, d *schema.ResourceData) (*god
opts.VPCUUID = v.(string)
}

if v, ok := d.GetOk("type"); ok {
opts.Type = v.(string)
}

return opts, nil
}

Expand Down Expand Up @@ -556,6 +560,7 @@ func resourceDigitalOceanLoadbalancerRead(ctx context.Context, d *schema.Resourc
d.Set("vpc_uuid", loadbalancer.VPCUUID)
d.Set("http_idle_timeout_seconds", loadbalancer.HTTPIdleTimeoutSeconds)
d.Set("project_id", loadbalancer.ProjectID)
d.Set("type", loadbalancer.Type)

if loadbalancer.SizeUnit > 0 {
d.Set("size_unit", loadbalancer.SizeUnit)
Expand Down Expand Up @@ -591,7 +596,6 @@ func resourceDigitalOceanLoadbalancerRead(ctx context.Context, d *schema.Resourc
}

return nil

}

func resourceDigitalOceanLoadbalancerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
5 changes: 5 additions & 0 deletions digitalocean/loadbalancer/resource_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestAccDigitalOceanLoadbalancer_Basic(t *testing.T) {
"digitalocean_loadbalancer.foobar", "name", name),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "region", "nyc3"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "type", "REGIONAL"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "size_unit", "1"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -93,6 +95,8 @@ func TestAccDigitalOceanLoadbalancer_Updated(t *testing.T) {
"digitalocean_loadbalancer.foobar", "name", name),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "region", "nyc3"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "type", "REGIONAL"),
resource.TestCheckResourceAttr(
"digitalocean_loadbalancer.foobar", "size_unit", "1"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -792,6 +796,7 @@ resource "digitalocean_droplet" "foobar" {
resource "digitalocean_loadbalancer" "foobar" {
name = "%s"
region = "nyc3"
type = "REGIONAL"
forwarding_rule {
entry_port = 80
Expand Down

0 comments on commit 77a29c7

Please sign in to comment.