Skip to content

Commit

Permalink
Magic Modules changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow authored and modular-magician committed Jun 28, 2018
1 parent cf44511 commit dd7ba7e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 28 deletions.
112 changes: 84 additions & 28 deletions google/resource_compute_target_https_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
compute "google.golang.org/api/compute/v1"
)

Expand Down Expand Up @@ -66,6 +67,11 @@ func resourceComputeTargetHttpsProxy() *schema.Resource {
Optional: true,
ForceNew: true,
},
"quic_override": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"NONE", "ENABLE", "DISABLE", ""}, false),
},
"ssl_policy": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -114,24 +120,30 @@ func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interfac
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
sslCertificatesProp, err := expandComputeTargetHttpsProxySslCertificates(d.Get("ssl_certificates"), d, config)
quicOverrideProp, err := expandComputeTargetHttpsProxyQuicOverride(d.Get("quic_override"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ssl_certificates"); !isEmptyValue(reflect.ValueOf(sslCertificatesProp)) && (ok || !reflect.DeepEqual(v, sslCertificatesProp)) {
obj["sslCertificates"] = sslCertificatesProp
} else if v, ok := d.GetOkExists("quic_override"); !isEmptyValue(reflect.ValueOf(quicOverrideProp)) && (ok || !reflect.DeepEqual(v, quicOverrideProp)) {
obj["quicOverride"] = quicOverrideProp
}
urlMapProp, err := expandComputeTargetHttpsProxyUrlMap(d.Get("url_map"), d, config)
sslCertificatesProp, err := expandComputeTargetHttpsProxySslCertificates(d.Get("ssl_certificates"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("url_map"); !isEmptyValue(reflect.ValueOf(urlMapProp)) && (ok || !reflect.DeepEqual(v, urlMapProp)) {
obj["urlMap"] = urlMapProp
} else if v, ok := d.GetOkExists("ssl_certificates"); !isEmptyValue(reflect.ValueOf(sslCertificatesProp)) && (ok || !reflect.DeepEqual(v, sslCertificatesProp)) {
obj["sslCertificates"] = sslCertificatesProp
}
sslPolicyProp, err := expandComputeTargetHttpsProxySslPolicy(d.Get("ssl_policy"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ssl_policy"); !isEmptyValue(reflect.ValueOf(sslPolicyProp)) && (ok || !reflect.DeepEqual(v, sslPolicyProp)) {
obj["sslPolicy"] = sslPolicyProp
}
urlMapProp, err := expandComputeTargetHttpsProxyUrlMap(d.Get("url_map"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("url_map"); !isEmptyValue(reflect.ValueOf(urlMapProp)) && (ok || !reflect.DeepEqual(v, urlMapProp)) {
obj["urlMap"] = urlMapProp
}

url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies")
if err != nil {
Expand Down Expand Up @@ -202,15 +214,18 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
if err := d.Set("name", flattenComputeTargetHttpsProxyName(res["name"])); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("ssl_certificates", flattenComputeTargetHttpsProxySslCertificates(res["sslCertificates"])); err != nil {
if err := d.Set("quic_override", flattenComputeTargetHttpsProxyQuicOverride(res["quicOverride"])); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("url_map", flattenComputeTargetHttpsProxyUrlMap(res["urlMap"])); err != nil {
if err := d.Set("ssl_certificates", flattenComputeTargetHttpsProxySslCertificates(res["sslCertificates"])); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("ssl_policy", flattenComputeTargetHttpsProxySslPolicy(res["sslPolicy"])); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("url_map", flattenComputeTargetHttpsProxyUrlMap(res["urlMap"])); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
Expand All @@ -235,16 +250,16 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac

d.Partial(true)

if d.HasChange("ssl_certificates") {
if d.HasChange("quic_override") {
obj := make(map[string]interface{})
sslCertificatesProp, err := expandComputeTargetHttpsProxySslCertificates(d.Get("ssl_certificates"), d, config)
quicOverrideProp, err := expandComputeTargetHttpsProxyQuicOverride(d.Get("quic_override"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ssl_certificates"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sslCertificatesProp)) {
obj["sslCertificates"] = sslCertificatesProp
} else if v, ok := d.GetOkExists("quic_override"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, quicOverrideProp)) {
obj["quicOverride"] = quicOverrideProp
}

url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setSslCertificates")
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}/setQuicOverride")
if err != nil {
return err
}
Expand All @@ -266,18 +281,18 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
return err
}

d.SetPartial("ssl_certificates")
d.SetPartial("quic_override")
}
if d.HasChange("url_map") {
if d.HasChange("ssl_certificates") {
obj := make(map[string]interface{})
urlMapProp, err := expandComputeTargetHttpsProxyUrlMap(d.Get("url_map"), d, config)
sslCertificatesProp, err := expandComputeTargetHttpsProxySslCertificates(d.Get("ssl_certificates"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("url_map"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, urlMapProp)) {
obj["urlMap"] = urlMapProp
} else if v, ok := d.GetOkExists("ssl_certificates"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sslCertificatesProp)) {
obj["sslCertificates"] = sslCertificatesProp
}

url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setUrlMap")
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setSslCertificates")
if err != nil {
return err
}
Expand All @@ -299,7 +314,7 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
return err
}

d.SetPartial("url_map")
d.SetPartial("ssl_certificates")
}
if d.HasChange("ssl_policy") {
obj := make(map[string]interface{})
Expand Down Expand Up @@ -334,6 +349,39 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac

d.SetPartial("ssl_policy")
}
if d.HasChange("url_map") {
obj := make(map[string]interface{})
urlMapProp, err := expandComputeTargetHttpsProxyUrlMap(d.Get("url_map"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("url_map"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, urlMapProp)) {
obj["urlMap"] = urlMapProp
}

url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setUrlMap")
if err != nil {
return err
}
res, err = sendRequest(config, "POST", url, obj)
if err != nil {
return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err)
}

err = Convert(res, op)
if err != nil {
return err
}

err = computeOperationWaitTime(
config.clientCompute, op, project, "Updating TargetHttpsProxy",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))

if err != nil {
return err
}

d.SetPartial("url_map")
}

d.Partial(false)

Expand Down Expand Up @@ -413,18 +461,22 @@ func flattenComputeTargetHttpsProxyName(v interface{}) interface{} {
return v
}

func flattenComputeTargetHttpsProxySslCertificates(v interface{}) interface{} {
func flattenComputeTargetHttpsProxyQuicOverride(v interface{}) interface{} {
return v
}

func flattenComputeTargetHttpsProxyUrlMap(v interface{}) interface{} {
func flattenComputeTargetHttpsProxySslCertificates(v interface{}) interface{} {
return v
}

func flattenComputeTargetHttpsProxySslPolicy(v interface{}) interface{} {
return v
}

func flattenComputeTargetHttpsProxyUrlMap(v interface{}) interface{} {
return v
}

func expandComputeTargetHttpsProxyDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand All @@ -433,6 +485,10 @@ func expandComputeTargetHttpsProxyName(v interface{}, d *schema.ResourceData, co
return v, nil
}

func expandComputeTargetHttpsProxyQuicOverride(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeTargetHttpsProxySslCertificates(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand All @@ -446,18 +502,18 @@ func expandComputeTargetHttpsProxySslCertificates(v interface{}, d *schema.Resou
return req, nil
}

func expandComputeTargetHttpsProxyUrlMap(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("urlMaps", v.(string), "project", d, config, true)
func expandComputeTargetHttpsProxySslPolicy(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("sslPolicies", v.(string), "project", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for url_map: %s", err)
return nil, fmt.Errorf("Invalid value for ssl_policy: %s", err)
}
return f.RelativeLink(), nil
}

func expandComputeTargetHttpsProxySslPolicy(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("sslPolicies", v.(string), "project", d, config, true)
func expandComputeTargetHttpsProxyUrlMap(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("urlMaps", v.(string), "project", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for ssl_policy: %s", err)
return nil, fmt.Errorf("Invalid value for url_map: %s", err)
}
return f.RelativeLink(), nil
}
1 change: 1 addition & 0 deletions google/resource_compute_target_https_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ resource "google_compute_target_https_proxy" "foobar" {
"${google_compute_ssl_certificate.foobar1.self_link}",
"${google_compute_ssl_certificate.foobar2.self_link}",
]
quic_override = "ENABLE"
}
resource "google_compute_backend_service" "foobar" {
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/compute_target_https_proxy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ The following arguments are supported:
* `description` -
(Optional)
An optional description of this resource.
* `quic_override` -
(Optional)
Specifies the QUIC override policy for this resource. This determines
whether the load balancer will attempt to negotiate QUIC with clients
or not. Can specify one of NONE, ENABLE, or DISABLE. Specify ENABLE to
always enable QUIC, Enables QUIC when set to ENABLE, and disables QUIC
when set to DISABLE. If NONE is specified, uses the QUIC policy with
no user overrides, which is equivalent to DISABLE. Not specifying this
field is equivalent to specifying NONE.
* `ssl_policy` -
(Optional)
A reference to the SslPolicy resource that will be associated with
Expand Down

0 comments on commit dd7ba7e

Please sign in to comment.