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 configuring Internal load balancer for Cloud Run for Anthos #7268

Merged
merged 10 commits into from
Sep 15, 2020

Conversation

ZhiminXiang
Copy link
Contributor

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.

@ghost ghost added the size/m label Sep 14, 2020
@ghost ghost requested a review from c2thorn September 14, 2020 18:33
@ZhiminXiang
Copy link
Contributor Author

/assign @danawillow

Copy link
Collaborator

@c2thorn c2thorn left a 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

@@ -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),
Copy link
Collaborator

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)

Copy link
Contributor Author

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

@@ -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"
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"disabled": c.CloudRunConfig.Disabled,
}
if c.CloudRunConfig.LoadBalancerType == "LOAD_BALANCER_TYPE_INTERNAL" {
cloudRunConfig["load_balancer_type"] = "internal"
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Comment on lines +2691 to +2696
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

@ZhiminXiang ZhiminXiang Sep 14, 2020

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

@c2thorn c2thorn left a 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

@ghost
Copy link

ghost commented Oct 16, 2020

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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants