Skip to content

Commit a7c8d04

Browse files
krotkiewiczrosbo
authored andcommitted
Add import support for ssl certificate, http/s proxy and url map (#678)
1 parent a871876 commit a7c8d04

13 files changed

+198
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package google
2+
3+
import (
4+
"github.com/hashicorp/terraform/helper/resource"
5+
"testing"
6+
)
7+
8+
func TestAccComputeSslCertificate_import(t *testing.T) {
9+
t.Parallel()
10+
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheck(t) },
13+
Providers: testAccProviders,
14+
CheckDestroy: testAccCheckComputeSslCertificateDestroy,
15+
Steps: []resource.TestStep{
16+
resource.TestStep{
17+
Config: testAccComputeSslCertificate_import,
18+
},
19+
resource.TestStep{
20+
ResourceName: "google_compute_ssl_certificate.foobar",
21+
ImportState: true,
22+
ImportStateVerify: true,
23+
ImportStateVerifyIgnore: []string{"private_key"},
24+
},
25+
},
26+
})
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
"github.com/hashicorp/terraform/helper/acctest"
6+
"github.com/hashicorp/terraform/helper/resource"
7+
"testing"
8+
)
9+
10+
func TestAccComputeTargetHttpProxy_import(t *testing.T) {
11+
t.Parallel()
12+
13+
target := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
14+
backend := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
15+
hc := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
16+
urlmap1 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
17+
urlmap2 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
18+
19+
resource.Test(t, resource.TestCase{
20+
PreCheck: func() { testAccPreCheck(t) },
21+
Providers: testAccProviders,
22+
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy,
23+
Steps: []resource.TestStep{
24+
resource.TestStep{
25+
Config: testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2),
26+
},
27+
resource.TestStep{
28+
ResourceName: "google_compute_target_http_proxy.foobar",
29+
ImportState: true,
30+
ImportStateVerify: true,
31+
},
32+
},
33+
})
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
"github.com/hashicorp/terraform/helper/acctest"
6+
"github.com/hashicorp/terraform/helper/resource"
7+
"testing"
8+
)
9+
10+
func TestAccComputeTargetHttpsProxy_import(t *testing.T) {
11+
t.Parallel()
12+
13+
id := fmt.Sprintf("thttps-test-%s", acctest.RandString(10))
14+
15+
resource.Test(t, resource.TestCase{
16+
PreCheck: func() { testAccPreCheck(t) },
17+
Providers: testAccProviders,
18+
CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroy,
19+
Steps: []resource.TestStep{
20+
resource.TestStep{
21+
Config: testAccComputeTargetHttpsProxy_basic1(id),
22+
},
23+
resource.TestStep{
24+
ResourceName: "google_compute_target_https_proxy.foobar",
25+
ImportState: true,
26+
ImportStateVerify: true,
27+
},
28+
},
29+
})
30+
}

google/import_compute_url_map_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package google
2+
3+
import (
4+
"fmt"
5+
"github.com/hashicorp/terraform/helper/acctest"
6+
"github.com/hashicorp/terraform/helper/resource"
7+
"testing"
8+
)
9+
10+
func TestAccComputeUrlMap_import(t *testing.T) {
11+
t.Parallel()
12+
13+
bsName := fmt.Sprintf("bs-test-%s", acctest.RandString(10))
14+
hcName := fmt.Sprintf("hc-test-%s", acctest.RandString(10))
15+
umName := fmt.Sprintf("um-test-%s", acctest.RandString(10))
16+
17+
resource.Test(t, resource.TestCase{
18+
PreCheck: func() { testAccPreCheck(t) },
19+
Providers: testAccProviders,
20+
CheckDestroy: testAccCheckComputeUrlMapDestroy,
21+
Steps: []resource.TestStep{
22+
resource.TestStep{
23+
Config: testAccComputeUrlMap_basic1(bsName, hcName, umName),
24+
},
25+
resource.TestStep{
26+
ResourceName: "google_compute_url_map.foobar",
27+
ImportState: true,
28+
ImportStateVerify: true,
29+
ImportStateVerifyIgnore: []string{"host_rule", "path_matcher", "test"},
30+
},
31+
}})
32+
}

google/resource_compute_ssl_certificate.go

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ func resourceComputeSslCertificate() *schema.Resource {
1515
Read: resourceComputeSslCertificateRead,
1616
Delete: resourceComputeSslCertificateDelete,
1717

18+
Importer: &schema.ResourceImporter{
19+
State: schema.ImportStatePassthrough,
20+
},
21+
1822
Schema: map[string]*schema.Schema{
1923
"certificate": &schema.Schema{
2024
Type: schema.TypeString,
@@ -141,6 +145,9 @@ func resourceComputeSslCertificateRead(d *schema.ResourceData, meta interface{})
141145

142146
d.Set("self_link", cert.SelfLink)
143147
d.Set("certificate_id", strconv.FormatUint(cert.Id, 10))
148+
d.Set("description", cert.Description)
149+
d.Set("name", cert.Name)
150+
d.Set("certificate", cert.Certificate)
144151

145152
return nil
146153
}

google/resource_compute_ssl_certificate_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,12 @@ resource "google_compute_ssl_certificate" "foobar" {
136136
certificate = "${file("test-fixtures/ssl_cert/test.crt")}"
137137
}
138138
`, acctest.RandString(10))
139+
140+
var testAccComputeSslCertificate_import = fmt.Sprintf(`
141+
resource "google_compute_ssl_certificate" "foobar" {
142+
name = "sslcert-test-%s"
143+
description = "very descriptive"
144+
private_key = "${file("test-fixtures/ssl_cert/test.key")}"
145+
certificate = "${file("test-fixtures/ssl_cert/test.crt")}"
146+
}
147+
`, acctest.RandString(10))

google/resource_compute_target_http_proxy.go

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ func resourceComputeTargetHttpProxy() *schema.Resource {
1616
Delete: resourceComputeTargetHttpProxyDelete,
1717
Update: resourceComputeTargetHttpProxyUpdate,
1818

19+
Importer: &schema.ResourceImporter{
20+
State: schema.ImportStatePassthrough,
21+
},
22+
1923
Schema: map[string]*schema.Schema{
2024
"name": &schema.Schema{
2125
Type: schema.TypeString,
@@ -135,6 +139,9 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{}
135139

136140
d.Set("self_link", proxy.SelfLink)
137141
d.Set("proxy_id", strconv.FormatUint(proxy.Id, 10))
142+
d.Set("description", proxy.Description)
143+
d.Set("url_map", proxy.UrlMap)
144+
d.Set("name", proxy.Name)
138145

139146
return nil
140147
}

google/resource_compute_target_https_proxy.go

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func resourceComputeTargetHttpsProxy() *schema.Resource {
2323
Delete: resourceComputeTargetHttpsProxyDelete,
2424
Update: resourceComputeTargetHttpsProxyUpdate,
2525

26+
Importer: &schema.ResourceImporter{
27+
State: schema.ImportStatePassthrough,
28+
},
29+
2630
Schema: map[string]*schema.Schema{
2731
"name": &schema.Schema{
2832
Type: schema.TypeString,
@@ -180,6 +184,9 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
180184
d.Set("ssl_certificates", proxy.SslCertificates)
181185
d.Set("proxy_id", strconv.FormatUint(proxy.Id, 10))
182186
d.Set("self_link", proxy.SelfLink)
187+
d.Set("description", proxy.Description)
188+
d.Set("url_map", proxy.UrlMap)
189+
d.Set("name", proxy.Name)
183190

184191
return nil
185192
}

google/resource_compute_url_map.go

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ func resourceComputeUrlMap() *schema.Resource {
1515
Update: resourceComputeUrlMapUpdate,
1616
Delete: resourceComputeUrlMapDelete,
1717

18+
Importer: &schema.ResourceImporter{
19+
State: resourceComputeUrlMapImportState,
20+
},
21+
1822
Schema: map[string]*schema.Schema{
1923
"default_service": &schema.Schema{
2024
Type: schema.TypeString,
@@ -317,6 +321,7 @@ func resourceComputeUrlMapRead(d *schema.ResourceData, meta interface{}) error {
317321
d.Set("self_link", urlMap.SelfLink)
318322
d.Set("map_id", strconv.FormatUint(urlMap.Id, 10))
319323
d.Set("fingerprint", urlMap.Fingerprint)
324+
d.Set("default_service", urlMap.DefaultService)
320325

321326
hostRuleMap := make(map[string]*compute.HostRule)
322327
for _, v := range urlMap.HostRules {
@@ -676,6 +681,11 @@ func resourceComputeUrlMapDelete(d *schema.ResourceData, meta interface{}) error
676681
return nil
677682
}
678683

684+
func resourceComputeUrlMapImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
685+
d.Set("name", d.Id())
686+
return []*schema.ResourceData{d}, nil
687+
}
688+
679689
func validateHostRules(v interface{}, k string) (ws []string, es []error) {
680690
pathMatchers := make(map[string]bool)
681691
hostRules := v.([]interface{})

website/docs/r/compute_ssl_certificate.html.markdown

+8
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,11 @@ exported:
9090

9191
[1]: /docs/providers/google/r/compute_target_https_proxy.html
9292
[2]: /docs/configuration/resources.html#lifecycle
93+
94+
## Import
95+
96+
SSL certificate can be imported using the `name`, e.g.
97+
98+
```
99+
$ terraform import compute_ssl_certificate.html.foobar foobar
100+
```

website/docs/r/compute_target_http_proxy.html.markdown

+8
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,11 @@ exported:
8989
* `proxy_id` - A unique ID assigned by GCE.
9090

9191
* `self_link` - The URI of the created resource.
92+
93+
## Import
94+
95+
Target HTTP Proxy can be imported using the `name`, e.g.
96+
97+
```
98+
$ terraform import compute_target_http_proxy.foobar foobar
99+
```

website/docs/r/compute_target_https_proxy.html.markdown

+8
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,11 @@ exported:
9999
* `proxy_id` - A unique ID assigned by GCE.
100100

101101
* `self_link` - The URI of the created resource.
102+
103+
## Import
104+
105+
Target HTTPS Proxy can be imported using the `name`, e.g.
106+
107+
```
108+
$ terraform import compute_target_https_proxy.foobar foobar
109+
```

website/docs/r/compute_url_map.html.markdown

+11
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,14 @@ exported:
160160
* `map_id` - The GCE assigned ID of the resource.
161161

162162
* `self_link` - The URI of the created resource.
163+
164+
## Import
165+
166+
URL Map can be imported using the `name`, e.g.
167+
168+
```
169+
$ terraform import google_compute_url_map.html.foobar foobar
170+
```
171+
172+
173+
Currently `host_rule`, `path_matcher` and `test` importing is not yet supported.

0 commit comments

Comments
 (0)