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

Add certificate_map to compute_target_https_proxy #4550

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/5991.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `certificate_map` to `compute_target_https_proxy` resource
```
82 changes: 71 additions & 11 deletions google-beta/resource_compute_target_https_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,21 @@ first character must be a lowercase letter, and all following
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.`,
},
"ssl_certificates": {
Type: schema.TypeList,
Required: true,
Description: `A list of SslCertificate resources that are used to authenticate
connections between users and the load balancer. At least one SSL
certificate must be specified.`,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
},
"url_map": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
Description: `A reference to the UrlMap resource that defines the mapping from URL
to the BackendService.`,
},
"certificate_map": {
Type: schema.TypeString,
Optional: true,
Description: `A reference to the CertificateMap resource uri that identifies a certificate map
associated with the given target proxy. This field can only be set for global target proxies.
Accepted format is '//certificatemanager.googleapis.com/projects/{project}/locations/{location}/certificateMaps/{resourceName}'.`,
ExactlyOneOf: []string{"ssl_certificates", "certificate_map"},
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -96,6 +93,18 @@ specified, uses the QUIC policy with no user overrides, which is
equivalent to DISABLE. Default value: "NONE" Possible values: ["NONE", "ENABLE", "DISABLE"]`,
Default: "NONE",
},
"ssl_certificates": {
Type: schema.TypeList,
Optional: true,
Description: `A list of SslCertificate resources that are used to authenticate
connections between users and the load balancer. At least one SSL
certificate must be specified.`,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
ExactlyOneOf: []string{"ssl_certificates", "certificate_map"},
},
"ssl_policy": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -161,6 +170,12 @@ func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interfac
} else if v, ok := d.GetOkExists("ssl_certificates"); !isEmptyValue(reflect.ValueOf(sslCertificatesProp)) && (ok || !reflect.DeepEqual(v, sslCertificatesProp)) {
obj["sslCertificates"] = sslCertificatesProp
}
certificateMapProp, err := expandComputeTargetHttpsProxyCertificateMap(d.Get("certificate_map"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("certificate_map"); !isEmptyValue(reflect.ValueOf(certificateMapProp)) && (ok || !reflect.DeepEqual(v, certificateMapProp)) {
obj["certificateMap"] = certificateMapProp
}
sslPolicyProp, err := expandComputeTargetHttpsProxySslPolicy(d.Get("ssl_policy"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -278,6 +293,9 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
if err := d.Set("ssl_certificates", flattenComputeTargetHttpsProxySslCertificates(res["sslCertificates"], d, config)); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("certificate_map", flattenComputeTargetHttpsProxyCertificateMap(res["certificateMap"], d, config)); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
if err := d.Set("ssl_policy", flattenComputeTargetHttpsProxySslPolicy(res["sslPolicy"], d, config)); err != nil {
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
}
Expand Down Expand Up @@ -379,6 +397,40 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
return err
}
}
if d.HasChange("certificate_map") {
obj := make(map[string]interface{})

certificateMapProp, err := expandComputeTargetHttpsProxyCertificateMap(d.Get("certificate_map"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("certificate_map"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, certificateMapProp)) {
obj["certificateMap"] = certificateMapProp
}

url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/targetHttpsProxies/{{name}}/setCertificateMap")
if err != nil {
return err
}

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err)
} else {
log.Printf("[DEBUG] Finished updating TargetHttpsProxy %q: %#v", d.Id(), res)
}

err = computeOperationWaitTime(
config, res, project, "Updating TargetHttpsProxy", userAgent,
d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
}
if d.HasChange("ssl_policy") {
obj := make(map[string]interface{})

Expand Down Expand Up @@ -562,6 +614,10 @@ func flattenComputeTargetHttpsProxySslCertificates(v interface{}, d *schema.Reso
return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1)
}

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

func flattenComputeTargetHttpsProxySslPolicy(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -608,6 +664,10 @@ func expandComputeTargetHttpsProxySslCertificates(v interface{}, d TerraformReso
return req, nil
}

func expandComputeTargetHttpsProxyCertificateMap(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeTargetHttpsProxySslPolicy(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("sslPolicies", v.(string), "project", d, config, true)
if err != nil {
Expand Down
96 changes: 96 additions & 0 deletions google-beta/resource_compute_target_https_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

const (
canonicalSslCertificateTemplate = "https://www.googleapis.com/compute/v1/projects/%s/global/sslCertificates/%s"
canonicalCertificateMapTemplate = "//certificatemanager.googleapis.com/projects/%s/locations/global/certificateMaps/%s"
)

func TestAccComputeTargetHttpsProxy_update(t *testing.T) {
Expand Down Expand Up @@ -48,6 +49,30 @@ func TestAccComputeTargetHttpsProxy_update(t *testing.T) {
})
}

func TestAccComputeTargetHttpsProxy_certificateMap(t *testing.T) {
t.Parallel()

var proxy compute.TargetHttpsProxy
resourceSuffix := randString(t, 10)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeTargetHttpsProxy_certificateMap(resourceSuffix),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetHttpsProxyExists(
t, "google_compute_target_https_proxy.foobar", &proxy),
testAccComputeTargetHttpsProxyDescription("Resource created for Terraform acceptance testing", &proxy),
testAccComputeTargetHttpsProxyHasCertificateMap(t, "certificatemap-test-"+resourceSuffix, &proxy),
),
},
},
})
}

func testAccCheckComputeTargetHttpsProxyExists(t *testing.T, n string, proxy *compute.TargetHttpsProxy) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -102,6 +127,19 @@ func testAccComputeTargetHttpsProxyHasSslCertificate(t *testing.T, cert string,
}
}

func testAccComputeTargetHttpsProxyHasCertificateMap(t *testing.T, certificateMap string, proxy *compute.TargetHttpsProxy) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := googleProviderConfig(t)
certificateMapUrl := fmt.Sprintf(canonicalCertificateMapTemplate, config.Project, certificateMap)

if ConvertSelfLinkToV1(proxy.CertificateMap) == certificateMapUrl {
return nil
}

return fmt.Errorf("certificate map not found: expected'%s'", certificateMapUrl)
}
}

func testAccComputeTargetHttpsProxy_basic1(id string) string {
return fmt.Sprintf(`
resource "google_compute_target_https_proxy" "foobar" {
Expand Down Expand Up @@ -238,3 +276,61 @@ resource "google_compute_ssl_certificate" "foobar2" {
}
`, id, id, id, id, id, id, id)
}

func testAccComputeTargetHttpsProxy_certificateMap(id string) string {
return fmt.Sprintf(`
resource "google_compute_target_https_proxy" "foobar" {
description = "Resource created for Terraform acceptance testing"
name = "httpsproxy-test-%s"
url_map = google_compute_url_map.foobar.self_link
certificate_map = "//certificatemanager.googleapis.com/${google_certificate_manager_certificate_map.map.id}"
}

resource "google_compute_backend_service" "foobar" {
name = "httpsproxy-test-backend-%s"
health_checks = [google_compute_http_health_check.zero.self_link]
}

resource "google_compute_http_health_check" "zero" {
name = "httpsproxy-test-health-check-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}

resource "google_compute_url_map" "foobar" {
name = "httpsproxy-test-url-map-%s"
default_service = google_compute_backend_service.foobar.self_link
}

resource "google_certificate_manager_certificate_map" "map" {
name = "certificatemap-test-%s"
}

resource "google_certificate_manager_certificate_map_entry" "map_entry" {
name = "certificatemapentry-test-%s"
map = google_certificate_manager_certificate_map.map.name
certificates = [google_certificate_manager_certificate.certificate.id]
matcher = "PRIMARY"
}

resource "google_certificate_manager_certificate" "certificate" {
name = "certificate-test-%s"
scope = "DEFAULT"
managed {
domains = [
google_certificate_manager_dns_authorization.instance.domain,
]
dns_authorizations = [
google_certificate_manager_dns_authorization.instance.id,
]
}
}

resource "google_certificate_manager_dns_authorization" "instance" {
name = "dnsauthorization-test-%s"
domain = "mysite.com"
}

`, id, id, id, id, id, id, id, id)
}
18 changes: 12 additions & 6 deletions website/docs/r/compute_target_https_proxy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ The following arguments are supported:
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.

* `ssl_certificates` -
(Required)
A list of SslCertificate resources that are used to authenticate
connections between users and the load balancer. At least one SSL
certificate must be specified.

* `url_map` -
(Required)
A reference to the UrlMap resource that defines the mapping from URL
Expand All @@ -135,6 +129,18 @@ The following arguments are supported:
Default value is `NONE`.
Possible values are `NONE`, `ENABLE`, and `DISABLE`.

* `ssl_certificates` -
(Optional)
A list of SslCertificate resources that are used to authenticate
connections between users and the load balancer. At least one SSL
certificate must be specified.

* `certificate_map` -
(Optional)
A reference to the CertificateMap resource uri that identifies a certificate map
associated with the given target proxy. This field can only be set for global target proxies.
Accepted format is `//certificatemanager.googleapis.com/projects/{project}/locations/{location}/certificateMaps/{resourceName}`.

* `ssl_policy` -
(Optional)
A reference to the SslPolicy resource that will be associated with
Expand Down