Skip to content

Commit

Permalink
Promote user_ip_request_headers field on `google_compute_security_p…
Browse files Browse the repository at this point in the history
…olicy` resource to GA (#9872)
  • Loading branch information
SarahFrench authored Feb 13, 2024
1 parent 1d3073d commit 379d462
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"context"
"fmt"
"log"
<% unless version == 'ga' -%>
"strings"
<% end -%>

"time"

Expand Down Expand Up @@ -466,14 +464,12 @@ func ResourceComputeSecurityPolicy() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{"NORMAL", "VERBOSE"}, false),
Description: `Logging level. Supported values include: "NORMAL", "VERBOSE".`,
},
<% unless version == 'ga' -%>
"user_ip_request_headers": {
Type: schema.TypeSet,
Optional: true,
Description: `An optional list of case-insensitive request header names to use for resolving the callers client IP address.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
<% end -%>
},
},
},
Expand Down Expand Up @@ -742,9 +738,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{
Fingerprint: d.Get("fingerprint").(string),
}

<% unless version == 'ga' -%>
updateMask := []string{}
<% end -%>

if d.HasChange("type") {
securityPolicy.Type = d.Get("type").(string)
Expand All @@ -759,13 +753,11 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{
if d.HasChange("advanced_options_config") {
securityPolicy.AdvancedOptionsConfig = expandSecurityPolicyAdvancedOptionsConfig(d.Get("advanced_options_config").([]interface{}))
securityPolicy.ForceSendFields = append(securityPolicy.ForceSendFields, "AdvancedOptionsConfig", "advancedOptionsConfig.jsonParsing", "advancedOptionsConfig.jsonCustomConfig", "advancedOptionsConfig.logLevel")
<% unless version == 'ga' -%>
securityPolicy.ForceSendFields = append(securityPolicy.ForceSendFields, "advanceOptionConfig.userIpRequestHeaders")
if len(securityPolicy.AdvancedOptionsConfig.UserIpRequestHeaders) == 0 {
// to clean this list we must send the updateMask of this field on the request.
updateMask = append(updateMask, "advanced_options_config.user_ip_request_headers")
}
<% end -%>
}

if d.HasChange("adaptive_protection_config") {
Expand All @@ -784,11 +776,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{
if len(securityPolicy.ForceSendFields) > 0 {
client := config.NewComputeClient(userAgent)

<% if version == 'ga' -%>
op, err := client.SecurityPolicies.Patch(project, sp, securityPolicy).Do()
<% else -%>
op, err := client.SecurityPolicies.Patch(project, sp, securityPolicy).UpdateMask(strings.Join(updateMask, ",")).Do()
<% end -%>

if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error updating SecurityPolicy %q: {{err}}", sp), err)
Expand Down Expand Up @@ -1230,9 +1218,7 @@ func expandSecurityPolicyAdvancedOptionsConfig(configured []interface{}) *comput
JsonParsing: data["json_parsing"].(string),
JsonCustomConfig: expandSecurityPolicyAdvancedOptionsConfigJsonCustomConfig(data["json_custom_config"].([]interface{})),
LogLevel: data["log_level"].(string),
<% unless version == 'ga' -%>
UserIpRequestHeaders: tpgresource.ConvertStringArr(data["user_ip_request_headers"].(*schema.Set).List()),
<% end %>
}
}

Expand All @@ -1245,9 +1231,7 @@ func flattenSecurityPolicyAdvancedOptionsConfig(conf *compute.SecurityPolicyAdva
"json_parsing": conf.JsonParsing,
"json_custom_config": flattenSecurityPolicyAdvancedOptionsConfigJsonCustomConfig(conf.JsonCustomConfig),
"log_level": conf.LogLevel,
<% unless version == 'ga' -%>
"user_ip_request_headers": schema.NewSet(schema.HashString, tpgresource.ConvertStringArrToInterface(conf.UserIpRequestHeaders)),
<% end -%>
}

return []map[string]interface{}{data}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func TestAccComputeSecurityPolicy_withAdvancedOptionsConfig(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
<% unless version == 'ga' -%>
{
Config: testAccComputeSecurityPolicy_withAdvancedOptionsConfig_update(spName),
},
Expand All @@ -216,7 +215,6 @@ func TestAccComputeSecurityPolicy_withAdvancedOptionsConfig(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
<% end -%>
{
Config: testAccComputeSecurityPolicy_basic(spName),
},
Expand Down Expand Up @@ -1108,19 +1106,15 @@ resource "google_compute_security_policy" "policy" {
]
}
log_level = "VERBOSE"
<% unless version == 'ga' -%>
user_ip_request_headers = [
"True-Client-IP",
"x-custom-ip"
]
<% end -%>

}
}
`, spName)
}

<% unless version == 'ga' -%>
func testAccComputeSecurityPolicy_withAdvancedOptionsConfig_update(spName string) string {
return fmt.Sprintf(`
resource "google_compute_security_policy" "policy" {
Expand Down Expand Up @@ -1189,7 +1183,6 @@ resource "google_compute_security_policy" "policy" {
}
`, spName)
}
<% end -%>

func testAccComputeSecurityPolicy_withAdaptiveProtection(spName string) string {
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ The following arguments are supported:
* `NORMAL` - Normal log level.
* `VERBOSE` - Verbose log level.

* `user_ip_request_headers` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) An optional list of case-insensitive request header names to use for resolving the callers client IP address.
* `user_ip_request_headers` - (Optional) An optional list of case-insensitive request header names to use for resolving the callers client IP address.

<a name="nested_json_custom_config"></a>The `json_custom_config` block supports:

Expand Down

0 comments on commit 379d462

Please sign in to comment.