Repository: digitalocean/doctl
Pull request #1309 (2022-11-15 21:26:49)

LBAAS-2450 Support project id for loadbalancers
Support Project ID in DOCTL


Patch:
diff --git a/commands/load_balancers.go b/commands/load_balancers.go
index cb834ae8..daa3f61a 100644
--- a/commands/load_balancers.go
+++ b/commands/load_balancers.go
@@ -84,6 +84,7 @@ With the load-balancer command, you can list, create, or delete load balancers,
 	AddStringFlag(cmdRecordCreate, doctl.ArgForwardingRules, "", "",
 		forwardingRulesTxt)
 	AddBoolFlag(cmdRecordCreate, doctl.ArgCommandWait, "", false, "Boolean that specifies whether to wait for a load balancer to complete before returning control to the terminal")
+	AddStringFlag(cmdRecordCreate, doctl.ArgProjectID, "", "", "Indicates which project to associate the Load Balancer with. If not specified, the Load Balancer will be placed in your default project.")
 
 	cmdRecordUpdate := CmdBuilder(cmd, RunLoadBalancerUpdate, "update <id>",
 		"Update a load balancer's configuration", `Use this command to update the configuration of a specified load balancer.`, Writer, aliasOpt("u"))
@@ -114,6 +115,8 @@ With the load-balancer command, you can list, create, or delete load balancers,
 	AddStringFlag(cmdRecordUpdate, doctl.ArgForwardingRules, "", "", forwardingRulesTxt)
 	AddBoolFlag(cmdRecordUpdate, doctl.ArgDisableLetsEncryptDNSRecords, "", false,
 		"disable automatic DNS record creation for Let's Encrypt certificates that are added to the load balancer")
+	AddStringFlag(cmdRecordUpdate, doctl.ArgProjectID, "", "",
+		"Indicates which project to associate the Load Balancer with. If not specified, the Load Balancer will be placed in your default project.")
 
 	CmdBuilder(cmd, RunLoadBalancerList, "list", "List load balancers", "Use this command to get a list of the load balancers on your account, including the following information for each:\n\n"+lbDetail, Writer,
 		aliasOpt("ls"), displayerType(&displayers.LoadBalancer{}))
@@ -519,6 +522,13 @@ func buildRequestFromArgs(c *CmdConfig, r *godo.LoadBalancerRequest) error {
 	}
 	r.ForwardingRules = forwardingRules
 
+	projectID, err := c.Doit.GetString(c.NS, doctl.ArgProjectID)
+	if err != nil {
+		return err
+	}
+
+	r.ProjectID = projectID
+
 	return nil
 }
 


Test patch:
diff --git a/commands/load_balancers_test.go b/commands/load_balancers_test.go
index bb5be5ef..bab3bd46 100644
--- a/commands/load_balancers_test.go
+++ b/commands/load_balancers_test.go
@@ -107,7 +107,8 @@ func TestLoadBalancerCreate(t *testing.T) {
 					TlsPassthrough: true,
 				},
 			},
-			VPCUUID: vpcUUID,
+			VPCUUID:   vpcUUID,
+			ProjectID: "project-id-uuid",
 		}
 		disableLetsEncryptDNSRecords := true
 		r.DisableLetsEncryptDNSRecords = &disableLetsEncryptDNSRecords
@@ -122,6 +123,7 @@ func TestLoadBalancerCreate(t *testing.T) {
 		config.Doit.Set(config.NS, doctl.ArgHealthCheck, "protocol:http,port:80,check_interval_seconds:4,response_timeout_seconds:23,healthy_threshold:5,unhealthy_threshold:10")
 		config.Doit.Set(config.NS, doctl.ArgForwardingRules, "entry_protocol:tcp,entry_port:3306,target_protocol:tcp,target_port:3306,tls_passthrough:true")
 		config.Doit.Set(config.NS, doctl.ArgDisableLetsEncryptDNSRecords, true)
+		config.Doit.Set(config.NS, doctl.ArgProjectID, "project-id-uuid")
 
 		err := RunLoadBalancerCreate(config)
 		assert.NoError(t, err)
@@ -157,6 +159,7 @@ func TestLoadBalancerUpdate(t *testing.T) {
 					TargetPort:     80,
 				},
 			},
+			ProjectID: "project-id-uuid",
 		}
 		disableLetsEncryptDNSRecords := true
 		r.DisableLetsEncryptDNSRecords = &disableLetsEncryptDNSRecords
@@ -172,6 +175,7 @@ func TestLoadBalancerUpdate(t *testing.T) {
 		config.Doit.Set(config.NS, doctl.ArgHealthCheck, "protocol:http,port:80,check_interval_seconds:4,response_timeout_seconds:23,healthy_threshold:5,unhealthy_threshold:10")
 		config.Doit.Set(config.NS, doctl.ArgForwardingRules, "entry_protocol:http,entry_port:80,target_protocol:http,target_port:80")
 		config.Doit.Set(config.NS, doctl.ArgDisableLetsEncryptDNSRecords, true)
+		config.Doit.Set(config.NS, doctl.ArgProjectID, "project-id-uuid")
 
 		err := RunLoadBalancerUpdate(config)
 		assert.NoError(t, err)