Skip to content

Commit da0b6f9

Browse files
modular-magicianrosbo
authored andcommitted
Add support for ssl_policy to google_target_https_proxy (#1466)
1 parent 560e180 commit da0b6f9

3 files changed

+78
-2
lines changed

google/resource_compute_target_https_proxy.go

+58
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func resourceComputeTargetHttpsProxy() *schema.Resource {
6565
Optional: true,
6666
ForceNew: true,
6767
},
68+
"ssl_policy": {
69+
Type: schema.TypeString,
70+
Optional: true,
71+
DiffSuppressFunc: compareSelfLinkOrResourceName,
72+
},
6873
"creation_timestamp": {
6974
Type: schema.TypeString,
7075
Computed: true,
@@ -111,12 +116,17 @@ func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interfac
111116
if err != nil {
112117
return err
113118
}
119+
sslPolicyProp, err := expandComputeTargetHttpsProxySslPolicy(d.Get("ssl_policy"), d, config)
120+
if err != nil {
121+
return err
122+
}
114123

115124
obj := map[string]interface{}{
116125
"description": descriptionProp,
117126
"name": nameProp,
118127
"sslCertificates": sslCertificatesProp,
119128
"urlMap": urlMapProp,
129+
"sslPolicy": sslPolicyProp,
120130
}
121131

122132
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies")
@@ -191,6 +201,9 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
191201
if err := d.Set("url_map", flattenComputeTargetHttpsProxyUrlMap(res["urlMap"])); err != nil {
192202
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
193203
}
204+
if err := d.Set("ssl_policy", flattenComputeTargetHttpsProxySslPolicy(res["sslPolicy"])); err != nil {
205+
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
206+
}
194207
if err := d.Set("self_link", res["selfLink"]); err != nil {
195208
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
196209
}
@@ -281,6 +294,39 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
281294

282295
d.SetPartial("url_map")
283296
}
297+
if d.HasChange("ssl_policy") {
298+
sslPolicyProp, err := expandComputeTargetHttpsProxySslPolicy(d.Get("ssl_policy"), d, config)
299+
if err != nil {
300+
return err
301+
}
302+
303+
obj := map[string]interface{}{
304+
"sslPolicy": sslPolicyProp,
305+
}
306+
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}/setSslPolicy")
307+
if err != nil {
308+
return err
309+
}
310+
res, err = sendRequest(config, "POST", url, obj)
311+
if err != nil {
312+
return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err)
313+
}
314+
315+
err = Convert(res, op)
316+
if err != nil {
317+
return err
318+
}
319+
320+
err = computeOperationWaitTime(
321+
config.clientCompute, op, project, "Updating TargetHttpsProxy",
322+
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
323+
324+
if err != nil {
325+
return err
326+
}
327+
328+
d.SetPartial("ssl_policy")
329+
}
284330

285331
d.Partial(false)
286332

@@ -367,6 +413,10 @@ func flattenComputeTargetHttpsProxyUrlMap(v interface{}) interface{} {
367413
return v
368414
}
369415

416+
func flattenComputeTargetHttpsProxySslPolicy(v interface{}) interface{} {
417+
return v
418+
}
419+
370420
func expandComputeTargetHttpsProxyDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
371421
return v, nil
372422
}
@@ -395,3 +445,11 @@ func expandComputeTargetHttpsProxyUrlMap(v interface{}, d *schema.ResourceData,
395445
}
396446
return f.RelativeLink(), nil
397447
}
448+
449+
func expandComputeTargetHttpsProxySslPolicy(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
450+
f, err := parseGlobalFieldValue("sslPolicies", v.(string), "project", d, config, true)
451+
if err != nil {
452+
return nil, fmt.Errorf("Invalid value for ssl_policy: %s", err)
453+
}
454+
return f.RelativeLink(), nil
455+
}

google/resource_compute_target_https_proxy_test.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ resource "google_compute_target_https_proxy" "foobar" {
156156
name = "httpsproxy-test-%s"
157157
url_map = "${google_compute_url_map.foobar.self_link}"
158158
ssl_certificates = ["${google_compute_ssl_certificate.foobar1.self_link}"]
159+
ssl_policy = "${google_compute_ssl_policy.foobar.self_link}"
159160
}
160161
161162
resource "google_compute_backend_service" "foobar" {
@@ -192,6 +193,13 @@ resource "google_compute_url_map" "foobar" {
192193
}
193194
}
194195
196+
resource "google_compute_ssl_policy" "foobar" {
197+
name = "sslproxy-test-%s"
198+
description = "my-description"
199+
min_tls_version = "TLS_1_2"
200+
profile = "MODERN"
201+
}
202+
195203
resource "google_compute_ssl_certificate" "foobar1" {
196204
name = "httpsproxy-test-cert1-%s"
197205
description = "very descriptive"
@@ -205,7 +213,7 @@ resource "google_compute_ssl_certificate" "foobar2" {
205213
private_key = "${file("test-fixtures/ssl_cert/test.key")}"
206214
certificate = "${file("test-fixtures/ssl_cert/test.crt")}"
207215
}
208-
`, id, id, id, id, id, id)
216+
`, id, id, id, id, id, id, id)
209217
}
210218

211219
func testAccComputeTargetHttpsProxy_basic2(id string) string {
@@ -254,6 +262,13 @@ resource "google_compute_url_map" "foobar" {
254262
}
255263
}
256264
265+
resource "google_compute_ssl_policy" "foobar" {
266+
name = "sslproxy-test-%s"
267+
description = "my-description"
268+
min_tls_version = "TLS_1_2"
269+
profile = "MODERN"
270+
}
271+
257272
resource "google_compute_ssl_certificate" "foobar1" {
258273
name = "httpsproxy-test-cert1-%s"
259274
description = "very descriptive"
@@ -267,5 +282,5 @@ resource "google_compute_ssl_certificate" "foobar2" {
267282
private_key = "${file("test-fixtures/ssl_cert/test.key")}"
268283
certificate = "${file("test-fixtures/ssl_cert/test.crt")}"
269284
}
270-
`, id, id, id, id, id, id)
285+
`, id, id, id, id, id, id, id)
271286
}

website/docs/r/compute_target_https_proxy.html.markdown

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ one SSL certificate must be specified.
115115
* `description` -
116116
(Optional)
117117
An optional description of this resource.
118+
* `ssl_policy` -
119+
(Optional)
120+
A reference to SslPolicy resource
118121
* `project` (Optional) The ID of the project in which the resource belongs.
119122
If it is not provided, the provider project is used.
120123

0 commit comments

Comments
 (0)