Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lb type param on terraform sdk #1023

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions digitalocean/loadbalancer/datasource_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
},
},
}
}
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 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", ""),
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", ""),
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", ""),
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", ""),
resource.TestCheckResourceAttr(
"data.digitalocean_loadbalancer.foobar", "forwarding_rule.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(
Expand Down Expand Up @@ -651,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"
Expand All @@ -663,6 +671,7 @@ resource "digitalocean_loadbalancer" "foo" {
name = "%s"
region = "nyc3"
size = "%s"
type = "REGIONAL"

forwarding_rule {
entry_port = 80
Expand Down Expand Up @@ -690,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"
Expand Down
11 changes: 10 additions & 1 deletion digitalocean/loadbalancer/resource_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ func resourceDigitalOceanLoadBalancerV0() *schema.Resource {
},
},
},
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "the type of the load balancer (GLOBAL or REGIONAL)",
},
},
}
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -591,7 +601,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
8 changes: 8 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(
asaha2 marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -136,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(
Expand Down Expand Up @@ -792,6 +798,7 @@ resource "digitalocean_droplet" "foobar" {
resource "digitalocean_loadbalancer" "foobar" {
name = "%s"
region = "nyc3"
type = "REGIONAL"

forwarding_rule {
entry_port = 80
Expand Down Expand Up @@ -833,6 +840,7 @@ resource "digitalocean_droplet" "foo" {
resource "digitalocean_loadbalancer" "foobar" {
name = "%s"
region = "nyc3"
type = "REGIONAL"

forwarding_rule {
entry_port = 81
Expand Down
Loading