-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 configuring Internal load balancer for Cloud Run for Anthos #7268
Support configuring Internal load balancer for Cloud Run for Anthos #7268
Conversation
/assign @danawillow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall pretty solid, but I have a couple of concerns about the enum value. Also, do you mind adding a "The cloudrun_config
block supports:" documentation bit here:
https://github.com/hashicorp/terraform-provider-google/blob/master/website/docs/r/container_cluster.html.markdown#argument-reference
google/resource_container_cluster.go
Outdated
@@ -274,6 +274,11 @@ func resourceContainerCluster() *schema.Resource { | |||
Type: schema.TypeBool, | |||
Required: true, | |||
}, | |||
"load_balancer_type": { | |||
Type: schema.TypeString, | |||
ValidateFunc: validation.StringInSlice([]string{"internal"}, true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe generally we pass the API accepted values through verbatim. Whenever additional settings come around, do you have an idea if they will follow the same naming convention?
I'd rather see LOAD_BALANCER_TYPE_INTERNAL
here, or at the very least forcing all caps INTERNAL
(for reasons below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Switched to LOAD_BALANCER_TYPE_INTERNAL
google/resource_container_cluster.go
Outdated
@@ -2298,6 +2303,10 @@ func expandClusterAddonsConfig(configured interface{}) *containerBeta.AddonsConf | |||
Disabled: addon["disabled"].(bool), | |||
ForceSendFields: []string{"Disabled"}, | |||
} | |||
if addon["load_balancer_type"] != "" { | |||
// Currently we only allow setting load_balancer_type to INTERNAL | |||
ac.CloudRunConfig.LoadBalancerType = "LOAD_BALANCER_TYPE_INTERNAL" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be easier to add more values in the future if we pass through the addon["load_balancer_type"]
value here and let the ValidateFunc
handle validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
google/resource_container_cluster.go
Outdated
"disabled": c.CloudRunConfig.Disabled, | ||
} | ||
if c.CloudRunConfig.LoadBalancerType == "LOAD_BALANCER_TYPE_INTERNAL" { | ||
cloudRunConfig["load_balancer_type"] = "internal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are hardcoding "internal" here, setting the balancer type to "INTERNAL" will result in a permanent diff. We should commit to one, or pass through the full LOAD_BALANCER_TYPE_INTERNAL
which will allow us to get rid of the if condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Yea, changed it to LOAD_BALANCER_TYPE_INTERNAL
cloudRunConfig := map[string]interface{}{ | ||
"disabled": c.CloudRunConfig.Disabled, | ||
} | ||
if c.CloudRunConfig.LoadBalancerType == "LOAD_BALANCER_TYPE_INTERNAL" { | ||
// Currently we only allow setting load_balancer_type to LOAD_BALANCER_TYPE_INTERNAL | ||
cloudRunConfig["load_balancer_type"] = "LOAD_BALANCER_TYPE_INTERNAL" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cloudRunConfig := map[string]interface{}{ | |
"disabled": c.CloudRunConfig.Disabled, | |
} | |
if c.CloudRunConfig.LoadBalancerType == "LOAD_BALANCER_TYPE_INTERNAL" { | |
// Currently we only allow setting load_balancer_type to LOAD_BALANCER_TYPE_INTERNAL | |
cloudRunConfig["load_balancer_type"] = "LOAD_BALANCER_TYPE_INTERNAL" | |
cloudRunConfig := map[string]interface{}{ | |
"disabled": c.CloudRunConfig.Disabled, | |
"load_balancer_type": c.CloudRunConfig.LoadBalancerType, |
now that we are passing the API value through, we don't need the if statement anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still want to keep the if
check because the server side will return LOAD_BALANCER_TYPE_EXTERNAL
for external case when not setting load_balancer_type
which we don't want to return and store into state file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay if we store it in state file? Terraform can handle this situation if we set the field schema as Computed: true
If the user doesn't explicitly state load_balancer_type
and the API returns it, setting the field to computed will allow Terraform to default to the API value and not cause any diffs.
Otherwise, we can keep the if and ignore LOAD_BALANCER_TYPE_EXTERNAL
. I'm fine either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @c2thorn. I will just keep it as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll work on getting this upstreamed to Magic Modules
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
This PR enables Terraform to configure internal load balancer for Cloud Run for Anthos.
This PR won't change the default behavior of Cloud Run, i.e. if users do not set
load_balancer_type
, they will get external load balancer which is the default behavior.If users want to use internal load balancer, they can set
load_balancer_type: internal
to get it.