2018-05-02 17:01:37 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file is automatically generated by Magic Modules and manual
|
|
|
|
// changes will be clobbered when the file is regenerated.
|
|
|
|
//
|
|
|
|
// Please read more about how to change this file in
|
|
|
|
// .github/CONTRIBUTING.md.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2015-11-02 19:32:07 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2018-06-19 20:56:06 +00:00
|
|
|
"reflect"
|
2017-09-25 14:23:46 +00:00
|
|
|
"strconv"
|
2018-05-02 17:01:37 +00:00
|
|
|
"time"
|
2017-09-25 14:23:46 +00:00
|
|
|
|
2015-11-02 19:32:07 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2018-06-29 22:24:27 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/validation"
|
2018-05-02 17:01:37 +00:00
|
|
|
compute "google.golang.org/api/compute/v1"
|
2015-11-02 19:32:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func resourceComputeTargetHttpsProxy() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Create: resourceComputeTargetHttpsProxyCreate,
|
|
|
|
Read: resourceComputeTargetHttpsProxyRead,
|
|
|
|
Update: resourceComputeTargetHttpsProxyUpdate,
|
2018-05-02 17:01:37 +00:00
|
|
|
Delete: resourceComputeTargetHttpsProxyDelete,
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2017-11-09 18:16:57 +00:00
|
|
|
Importer: &schema.ResourceImporter{
|
2018-05-02 17:01:37 +00:00
|
|
|
State: resourceComputeTargetHttpsProxyImport,
|
|
|
|
},
|
|
|
|
|
|
|
|
Timeouts: &schema.ResourceTimeout{
|
|
|
|
Create: schema.DefaultTimeout(240 * time.Second),
|
|
|
|
Update: schema.DefaultTimeout(240 * time.Second),
|
|
|
|
Delete: schema.DefaultTimeout(240 * time.Second),
|
2017-11-09 18:16:57 +00:00
|
|
|
},
|
|
|
|
|
2015-11-02 19:32:07 +00:00
|
|
|
Schema: map[string]*schema.Schema{
|
2018-05-02 17:01:37 +00:00
|
|
|
"name": {
|
2015-11-02 19:32:07 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-05-02 17:01:37 +00:00
|
|
|
"ssl_certificates": {
|
2016-04-10 21:34:15 +00:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Required: true,
|
2017-07-19 20:49:14 +00:00
|
|
|
Elem: &schema.Schema{
|
2018-01-31 00:07:43 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
DiffSuppressFunc: compareSelfLinkOrResourceName,
|
2017-07-19 20:49:14 +00:00
|
|
|
},
|
2016-04-10 21:34:15 +00:00
|
|
|
},
|
2018-05-02 17:01:37 +00:00
|
|
|
"url_map": {
|
2018-03-27 22:38:32 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
2018-05-02 17:01:37 +00:00
|
|
|
DiffSuppressFunc: compareSelfLinkOrResourceName,
|
2016-04-10 21:34:15 +00:00
|
|
|
},
|
2018-05-02 17:01:37 +00:00
|
|
|
"description": {
|
2015-11-02 19:32:07 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-06-29 22:24:27 +00:00
|
|
|
"quic_override": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ValidateFunc: validation.StringInSlice([]string{"NONE", "ENABLE", "DISABLE", ""}, false),
|
|
|
|
},
|
2018-05-09 22:55:17 +00:00
|
|
|
"ssl_policy": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DiffSuppressFunc: compareSelfLinkOrResourceName,
|
|
|
|
},
|
2018-05-02 17:01:37 +00:00
|
|
|
"creation_timestamp": {
|
2015-11-02 19:32:07 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2018-05-02 17:01:37 +00:00
|
|
|
"proxy_id": {
|
|
|
|
Type: schema.TypeInt,
|
2017-09-25 14:23:46 +00:00
|
|
|
Computed: true,
|
|
|
|
},
|
2018-05-02 17:01:37 +00:00
|
|
|
"project": {
|
2016-04-10 16:59:57 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2017-11-28 00:32:20 +00:00
|
|
|
Computed: true,
|
2016-04-10 16:59:57 +00:00
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-05-02 17:01:37 +00:00
|
|
|
"self_link": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2015-11-02 19:32:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-19 20:56:06 +00:00
|
|
|
obj := make(map[string]interface{})
|
2018-05-02 17:01:37 +00:00
|
|
|
descriptionProp, err := expandComputeTargetHttpsProxyDescription(d.Get("description"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["description"] = descriptionProp
|
2018-05-02 17:01:37 +00:00
|
|
|
}
|
|
|
|
nameProp, err := expandComputeTargetHttpsProxyName(d.Get("name"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["name"] = nameProp
|
2018-05-02 17:01:37 +00:00
|
|
|
}
|
2018-06-29 22:24:27 +00:00
|
|
|
quicOverrideProp, err := expandComputeTargetHttpsProxyQuicOverride(d.Get("quic_override"), d, config)
|
2018-05-02 17:01:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-29 22:24:27 +00:00
|
|
|
} else if v, ok := d.GetOkExists("quic_override"); !isEmptyValue(reflect.ValueOf(quicOverrideProp)) && (ok || !reflect.DeepEqual(v, quicOverrideProp)) {
|
|
|
|
obj["quicOverride"] = quicOverrideProp
|
2018-05-02 17:01:37 +00:00
|
|
|
}
|
2018-06-29 22:24:27 +00:00
|
|
|
sslCertificatesProp, err := expandComputeTargetHttpsProxySslCertificates(d.Get("ssl_certificates"), d, config)
|
2018-01-31 00:07:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-29 22:24:27 +00:00
|
|
|
} else if v, ok := d.GetOkExists("ssl_certificates"); !isEmptyValue(reflect.ValueOf(sslCertificatesProp)) && (ok || !reflect.DeepEqual(v, sslCertificatesProp)) {
|
|
|
|
obj["sslCertificates"] = sslCertificatesProp
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
2018-05-09 22:55:17 +00:00
|
|
|
sslPolicyProp, err := expandComputeTargetHttpsProxySslPolicy(d.Get("ssl_policy"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("ssl_policy"); !isEmptyValue(reflect.ValueOf(sslPolicyProp)) && (ok || !reflect.DeepEqual(v, sslPolicyProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["sslPolicy"] = sslPolicyProp
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
2018-06-29 22:24:27 +00:00
|
|
|
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
|
|
|
|
}
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
log.Printf("[DEBUG] Creating new TargetHttpsProxy: %#v", obj)
|
|
|
|
res, err := Post(config, url, obj)
|
2015-11-02 19:32:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating TargetHttpsProxy: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
// Store the ID now
|
|
|
|
id, err := replaceVars(d, config, "{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error constructing id: %s", err)
|
|
|
|
}
|
|
|
|
d.SetId(id)
|
|
|
|
|
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
2015-11-02 19:32:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
waitErr := computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Creating TargetHttpsProxy",
|
|
|
|
int(d.Timeout(schema.TimeoutCreate).Minutes()))
|
|
|
|
|
|
|
|
if waitErr != nil {
|
|
|
|
// The resource didn't actually create
|
|
|
|
d.SetId("")
|
|
|
|
return fmt.Errorf("Error waiting to create TargetHttpsProxy: %s", waitErr)
|
|
|
|
}
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2018-05-17 23:33:30 +00:00
|
|
|
log.Printf("[DEBUG] Finished creating TargetHttpsProxy %q: %#v", d.Id(), res)
|
|
|
|
|
2015-11-02 19:32:07 +00:00
|
|
|
return resourceComputeTargetHttpsProxyRead(d, meta)
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := Get(config, url)
|
|
|
|
if err != nil {
|
|
|
|
return handleNotFoundError(err, d, fmt.Sprintf("ComputeTargetHttpsProxy %q", d.Id()))
|
|
|
|
}
|
2018-05-17 23:33:30 +00:00
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
if err := d.Set("creation_timestamp", flattenComputeTargetHttpsProxyCreationTimestamp(res["creationTimestamp"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("description", flattenComputeTargetHttpsProxyDescription(res["description"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("proxy_id", flattenComputeTargetHttpsProxyProxyId(res["id"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("name", flattenComputeTargetHttpsProxyName(res["name"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
2018-06-29 22:24:27 +00:00
|
|
|
if err := d.Set("quic_override", flattenComputeTargetHttpsProxyQuicOverride(res["quicOverride"])); err != nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
2018-06-29 22:24:27 +00:00
|
|
|
if err := d.Set("ssl_certificates", flattenComputeTargetHttpsProxySslCertificates(res["sslCertificates"])); err != nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
2018-05-09 22:55:17 +00:00
|
|
|
if err := d.Set("ssl_policy", flattenComputeTargetHttpsProxySslPolicy(res["sslPolicy"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
2018-06-29 22:24:27 +00:00
|
|
|
if err := d.Set("url_map", flattenComputeTargetHttpsProxyUrlMap(res["urlMap"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
2018-06-12 00:31:33 +00:00
|
|
|
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("project", project); err != nil {
|
|
|
|
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-02 19:32:07 +00:00
|
|
|
func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
var url string
|
|
|
|
var res map[string]interface{}
|
|
|
|
op := &compute.Operation{}
|
|
|
|
|
2015-11-02 19:32:07 +00:00
|
|
|
d.Partial(true)
|
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
if d.HasChange("quic_override") {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj := make(map[string]interface{})
|
2018-06-29 22:24:27 +00:00
|
|
|
quicOverrideProp, err := expandComputeTargetHttpsProxyQuicOverride(d.Get("quic_override"), d, config)
|
2018-05-02 17:01:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-29 22:24:27 +00:00
|
|
|
} else if v, ok := d.GetOkExists("quic_override"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, quicOverrideProp)) {
|
|
|
|
obj["quicOverride"] = quicOverrideProp
|
2018-05-02 17:01:37 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}/setQuicOverride")
|
2015-11-02 19:32:07 +00:00
|
|
|
if err != nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
res, err = sendRequest(config, "POST", url, obj)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err)
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
err = Convert(res, op)
|
2015-11-02 19:32:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
err = computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Updating TargetHttpsProxy",
|
|
|
|
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
d.SetPartial("quic_override")
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
2018-06-29 22:24:27 +00:00
|
|
|
if d.HasChange("ssl_certificates") {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj := make(map[string]interface{})
|
2018-06-29 22:24:27 +00:00
|
|
|
sslCertificatesProp, err := expandComputeTargetHttpsProxySslCertificates(d.Get("ssl_certificates"), d, config)
|
2018-05-02 17:01:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-29 22:24:27 +00:00
|
|
|
} else if v, ok := d.GetOkExists("ssl_certificates"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sslCertificatesProp)) {
|
|
|
|
obj["sslCertificates"] = sslCertificatesProp
|
2018-05-02 17:01:37 +00:00
|
|
|
}
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setSslCertificates")
|
2018-01-31 00:07:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-05-02 17:01:37 +00:00
|
|
|
res, err = sendRequest(config, "POST", url, obj)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err)
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
2018-05-02 17:01:37 +00:00
|
|
|
|
|
|
|
err = Convert(res, op)
|
2015-11-02 19:32:07 +00:00
|
|
|
if err != nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return err
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
err = computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Updating TargetHttpsProxy",
|
|
|
|
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
|
|
|
|
|
2015-11-02 19:32:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
d.SetPartial("ssl_certificates")
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
2018-05-09 22:55:17 +00:00
|
|
|
if d.HasChange("ssl_policy") {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj := make(map[string]interface{})
|
2018-05-09 22:55:17 +00:00
|
|
|
sslPolicyProp, err := expandComputeTargetHttpsProxySslPolicy(d.Get("ssl_policy"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("ssl_policy"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sslPolicyProp)) {
|
|
|
|
obj["sslPolicy"] = sslPolicyProp
|
2018-05-09 22:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}/setSslPolicy")
|
|
|
|
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("ssl_policy")
|
|
|
|
}
|
2018-06-29 22:24:27 +00:00
|
|
|
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")
|
|
|
|
}
|
2015-11-02 19:32:07 +00:00
|
|
|
|
|
|
|
d.Partial(false)
|
|
|
|
|
|
|
|
return resourceComputeTargetHttpsProxyRead(d, meta)
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
func resourceComputeTargetHttpsProxyDelete(d *schema.ResourceData, meta interface{}) error {
|
2015-11-02 19:32:07 +00:00
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}")
|
2015-11-02 19:32:07 +00:00
|
|
|
if err != nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return err
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
log.Printf("[DEBUG] Deleting TargetHttpsProxy %q", d.Id())
|
|
|
|
res, err := Delete(config, url)
|
|
|
|
if err != nil {
|
2018-06-02 20:33:30 +00:00
|
|
|
return handleNotFoundError(err, d, "TargetHttpsProxy")
|
2018-05-02 17:01:37 +00:00
|
|
|
}
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
err = computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Deleting TargetHttpsProxy",
|
|
|
|
int(d.Timeout(schema.TimeoutDelete).Minutes()))
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-17 23:33:30 +00:00
|
|
|
log.Printf("[DEBUG] Finished deleting TargetHttpsProxy %q: %#v", d.Id(), res)
|
2018-05-02 17:01:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeTargetHttpsProxyImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
|
|
|
config := meta.(*Config)
|
|
|
|
parseImportId([]string{"projects/(?P<project>[^/]+)/global/targetHttpsProxies/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
|
|
|
|
|
|
|
|
// Replace import id for the resource id
|
|
|
|
id, err := replaceVars(d, config, "{{name}}")
|
2015-11-02 19:32:07 +00:00
|
|
|
if err != nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return nil, fmt.Errorf("Error constructing id: %s", err)
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
2018-05-02 17:01:37 +00:00
|
|
|
d.SetId(id)
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
return []*schema.ResourceData{d}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeTargetHttpsProxyCreationTimestamp(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeTargetHttpsProxyDescription(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeTargetHttpsProxyProxyId(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
2018-05-03 22:35:17 +00:00
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
2018-05-02 17:01:37 +00:00
|
|
|
return v
|
|
|
|
}
|
2015-11-02 19:32:07 +00:00
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
func flattenComputeTargetHttpsProxyName(v interface{}) interface{} {
|
|
|
|
return v
|
2015-11-02 19:32:07 +00:00
|
|
|
}
|
2018-04-19 18:01:33 +00:00
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
func flattenComputeTargetHttpsProxyQuicOverride(v interface{}) interface{} {
|
2018-05-02 17:01:37 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
func flattenComputeTargetHttpsProxySslCertificates(v interface{}) interface{} {
|
2018-07-18 21:24:21 +00:00
|
|
|
if v == nil {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1)
|
2018-05-02 17:01:37 +00:00
|
|
|
}
|
2018-04-19 18:01:33 +00:00
|
|
|
|
2018-05-09 22:55:17 +00:00
|
|
|
func flattenComputeTargetHttpsProxySslPolicy(v interface{}) interface{} {
|
2018-07-19 19:26:40 +00:00
|
|
|
if v == nil {
|
|
|
|
return v
|
|
|
|
}
|
2018-07-18 21:24:21 +00:00
|
|
|
return ConvertSelfLinkToV1(v.(string))
|
2018-05-09 22:55:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
func flattenComputeTargetHttpsProxyUrlMap(v interface{}) interface{} {
|
2018-07-19 19:26:40 +00:00
|
|
|
if v == nil {
|
|
|
|
return v
|
|
|
|
}
|
2018-07-18 21:24:21 +00:00
|
|
|
return ConvertSelfLinkToV1(v.(string))
|
2018-06-29 22:24:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
func expandComputeTargetHttpsProxyDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeTargetHttpsProxyName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
func expandComputeTargetHttpsProxyQuicOverride(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:01:37 +00:00
|
|
|
func expandComputeTargetHttpsProxySslCertificates(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
l := v.([]interface{})
|
|
|
|
req := make([]interface{}, 0, len(l))
|
|
|
|
for _, raw := range l {
|
|
|
|
f, err := parseGlobalFieldValue("sslCertificates", raw.(string), "project", d, config, true)
|
2018-04-19 18:01:33 +00:00
|
|
|
if err != nil {
|
2018-05-02 17:01:37 +00:00
|
|
|
return nil, fmt.Errorf("Invalid value for ssl_certificates: %s", err)
|
2018-04-19 18:01:33 +00:00
|
|
|
}
|
2018-05-02 17:01:37 +00:00
|
|
|
req = append(req, f.RelativeLink())
|
2018-04-19 18:01:33 +00:00
|
|
|
}
|
2018-05-02 17:01:37 +00:00
|
|
|
return req, nil
|
|
|
|
}
|
2018-04-19 18:01:33 +00:00
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
func expandComputeTargetHttpsProxySslPolicy(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
f, err := parseGlobalFieldValue("sslPolicies", v.(string), "project", d, config, true)
|
2018-05-02 17:01:37 +00:00
|
|
|
if err != nil {
|
2018-06-29 22:24:27 +00:00
|
|
|
return nil, fmt.Errorf("Invalid value for ssl_policy: %s", err)
|
2018-05-02 17:01:37 +00:00
|
|
|
}
|
|
|
|
return f.RelativeLink(), nil
|
2018-04-19 18:01:33 +00:00
|
|
|
}
|
2018-05-09 22:55:17 +00:00
|
|
|
|
2018-06-29 22:24:27 +00:00
|
|
|
func expandComputeTargetHttpsProxyUrlMap(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
f, err := parseGlobalFieldValue("urlMaps", v.(string), "project", d, config, true)
|
2018-05-09 22:55:17 +00:00
|
|
|
if err != nil {
|
2018-06-29 22:24:27 +00:00
|
|
|
return nil, fmt.Errorf("Invalid value for url_map: %s", err)
|
2018-05-09 22:55:17 +00:00
|
|
|
}
|
|
|
|
return f.RelativeLink(), nil
|
|
|
|
}
|