From 873b753b178e19f65f3aa96660d174f6c3f5514a Mon Sep 17 00:00:00 2001 From: Aditya Saha Date: Tue, 29 Aug 2023 09:24:28 -0400 Subject: [PATCH 1/3] Support lb type param on terraform sdk --- digitalocean/loadbalancer/datasource_loadbalancer.go | 7 +++++++ .../loadbalancer/datasource_loadbalancer_test.go | 9 +++++++++ digitalocean/loadbalancer/resource_loadbalancer.go | 12 +++++++++++- .../loadbalancer/resource_loadbalancer_test.go | 5 +++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/digitalocean/loadbalancer/datasource_loadbalancer.go b/digitalocean/loadbalancer/datasource_loadbalancer.go index 446e9ee5a..4ca29dbad 100644 --- a/digitalocean/loadbalancer/datasource_loadbalancer.go +++ b/digitalocean/loadbalancer/datasource_loadbalancer.go @@ -247,6 +247,12 @@ func DataSourceDigitalOceanLoadbalancer() *schema.Resource { }, }, }, + "type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "the type of the load balancer (GLOBAL or REGIONAL)", + }, }, } } @@ -323,6 +329,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) diff --git a/digitalocean/loadbalancer/datasource_loadbalancer_test.go b/digitalocean/loadbalancer/datasource_loadbalancer_test.go index d1601e243..57a87f96f 100644 --- a/digitalocean/loadbalancer/datasource_loadbalancer_test.go +++ b/digitalocean/loadbalancer/datasource_loadbalancer_test.go @@ -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", ""), resource.TestCheckResourceAttr( "data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"), resource.TestCheckTypeSetElemNestedAttrs( @@ -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", ""), resource.TestCheckResourceAttr( "data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"), resource.TestCheckTypeSetElemNestedAttrs( @@ -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", ""), resource.TestCheckResourceAttr( "data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"), resource.TestCheckTypeSetElemNestedAttrs( @@ -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", ""), resource.TestCheckResourceAttr( "data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"), resource.TestCheckTypeSetElemNestedAttrs( @@ -663,6 +671,7 @@ resource "digitalocean_loadbalancer" "foo" { name = "%s" region = "nyc3" size = "%s" + type = "REGIONAL" forwarding_rule { entry_port = 80 diff --git a/digitalocean/loadbalancer/resource_loadbalancer.go b/digitalocean/loadbalancer/resource_loadbalancer.go index ac034a2a6..b66328d42 100644 --- a/digitalocean/loadbalancer/resource_loadbalancer.go +++ b/digitalocean/loadbalancer/resource_loadbalancer.go @@ -403,6 +403,12 @@ func resourceDigitalOceanLoadBalancerV0() *schema.Resource { }, }, }, + "type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "the type of the load balancer (GLOBAL or REGIONAL)", + }, }, } } @@ -493,6 +499,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 } @@ -556,6 +566,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) @@ -591,7 +602,6 @@ func resourceDigitalOceanLoadbalancerRead(ctx context.Context, d *schema.Resourc } return nil - } func resourceDigitalOceanLoadbalancerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { diff --git a/digitalocean/loadbalancer/resource_loadbalancer_test.go b/digitalocean/loadbalancer/resource_loadbalancer_test.go index 87d43f2ed..1f4272449 100644 --- a/digitalocean/loadbalancer/resource_loadbalancer_test.go +++ b/digitalocean/loadbalancer/resource_loadbalancer_test.go @@ -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", ""), resource.TestCheckResourceAttr( "digitalocean_loadbalancer.foobar", "size_unit", "1"), resource.TestCheckResourceAttr( @@ -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", ""), resource.TestCheckResourceAttr( "digitalocean_loadbalancer.foobar", "size_unit", "1"), resource.TestCheckResourceAttr( @@ -792,6 +796,7 @@ resource "digitalocean_droplet" "foobar" { resource "digitalocean_loadbalancer" "foobar" { name = "%s" region = "nyc3" + type = "REGIONAL" forwarding_rule { entry_port = 80 From 94f9079ecd4f3dffa638abf584bf69f21f3be7dd Mon Sep 17 00:00:00 2001 From: Aditya Saha Date: Tue, 19 Sep 2023 12:05:23 -0400 Subject: [PATCH 2/3] Cleanup tests --- digitalocean/loadbalancer/datasource_loadbalancer_test.go | 4 ++-- digitalocean/loadbalancer/resource_loadbalancer.go | 2 -- digitalocean/loadbalancer/resource_loadbalancer_test.go | 7 +++++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/digitalocean/loadbalancer/datasource_loadbalancer_test.go b/digitalocean/loadbalancer/datasource_loadbalancer_test.go index 57a87f96f..145d724a5 100644 --- a/digitalocean/loadbalancer/datasource_loadbalancer_test.go +++ b/digitalocean/loadbalancer/datasource_loadbalancer_test.go @@ -659,7 +659,7 @@ resource "digitalocean_tag" "foo" { resource "digitalocean_droplet" "foo" { count = 2 - image = "ubuntu-18-04-x64" + image = "ubuntu-22-04-x64" name = "%s-${count.index}" region = "nyc3" size = "s-1vcpu-1gb" @@ -699,7 +699,7 @@ resource "digitalocean_tag" "foo" { resource "digitalocean_droplet" "foo" { count = 2 - image = "ubuntu-18-04-x64" + image = "ubuntu-22-04-x64" name = "%s-${count.index}" region = "nyc3" size = "s-1vcpu-1gb" diff --git a/digitalocean/loadbalancer/resource_loadbalancer.go b/digitalocean/loadbalancer/resource_loadbalancer.go index b66328d42..cd8759278 100644 --- a/digitalocean/loadbalancer/resource_loadbalancer.go +++ b/digitalocean/loadbalancer/resource_loadbalancer.go @@ -406,7 +406,6 @@ func resourceDigitalOceanLoadBalancerV0() *schema.Resource { "type": { Type: schema.TypeString, Optional: true, - Computed: true, Description: "the type of the load balancer (GLOBAL or REGIONAL)", }, }, @@ -566,7 +565,6 @@ 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) diff --git a/digitalocean/loadbalancer/resource_loadbalancer_test.go b/digitalocean/loadbalancer/resource_loadbalancer_test.go index 1f4272449..b6609c9bf 100644 --- a/digitalocean/loadbalancer/resource_loadbalancer_test.go +++ b/digitalocean/loadbalancer/resource_loadbalancer_test.go @@ -35,7 +35,7 @@ func TestAccDigitalOceanLoadbalancer_Basic(t *testing.T) { resource.TestCheckResourceAttr( "digitalocean_loadbalancer.foobar", "region", "nyc3"), resource.TestCheckResourceAttr( - "digitalocean_loadbalancer.foobar", "type", ""), + "digitalocean_loadbalancer.foobar", "type", "REGIONAL"), resource.TestCheckResourceAttr( "digitalocean_loadbalancer.foobar", "size_unit", "1"), resource.TestCheckResourceAttr( @@ -96,7 +96,7 @@ func TestAccDigitalOceanLoadbalancer_Updated(t *testing.T) { resource.TestCheckResourceAttr( "digitalocean_loadbalancer.foobar", "region", "nyc3"), resource.TestCheckResourceAttr( - "digitalocean_loadbalancer.foobar", "type", ""), + "digitalocean_loadbalancer.foobar", "type", "REGIONAL"), resource.TestCheckResourceAttr( "digitalocean_loadbalancer.foobar", "size_unit", "1"), resource.TestCheckResourceAttr( @@ -140,6 +140,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( @@ -838,6 +840,7 @@ resource "digitalocean_droplet" "foo" { resource "digitalocean_loadbalancer" "foobar" { name = "%s" region = "nyc3" + type = "REGIONAL" forwarding_rule { entry_port = 81 From 447d0d65982397f152ddd57e07062a8120a7de2c Mon Sep 17 00:00:00 2001 From: Aditya Saha Date: Wed, 20 Sep 2023 10:14:24 -0400 Subject: [PATCH 3/3] Update digitalocean/loadbalancer/resource_loadbalancer.go PR feedback Co-authored-by: Andrew Starr-Bochicchio --- digitalocean/loadbalancer/resource_loadbalancer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/digitalocean/loadbalancer/resource_loadbalancer.go b/digitalocean/loadbalancer/resource_loadbalancer.go index cd8759278..2b099249d 100644 --- a/digitalocean/loadbalancer/resource_loadbalancer.go +++ b/digitalocean/loadbalancer/resource_loadbalancer.go @@ -406,6 +406,7 @@ func resourceDigitalOceanLoadBalancerV0() *schema.Resource { "type": { Type: schema.TypeString, Optional: true, + ForceNew: true, Description: "the type of the load balancer (GLOBAL or REGIONAL)", }, },