Skip to content

Commit 8493072

Browse files
rosbomodular-magician
authored andcommitted
Release generated GlobalAddress
1 parent 31a5c9d commit 8493072

4 files changed

+224
-54
lines changed
+156-36
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,74 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
115
package google
216

317
import (
418
"fmt"
519
"log"
20+
"time"
621

722
"github.com/hashicorp/terraform/helper/schema"
823
"github.com/hashicorp/terraform/helper/validation"
9-
10-
"google.golang.org/api/compute/v1"
24+
compute "google.golang.org/api/compute/v1"
1125
)
1226

1327
func resourceComputeGlobalAddress() *schema.Resource {
1428
return &schema.Resource{
1529
Create: resourceComputeGlobalAddressCreate,
1630
Read: resourceComputeGlobalAddressRead,
1731
Delete: resourceComputeGlobalAddressDelete,
32+
1833
Importer: &schema.ResourceImporter{
19-
State: schema.ImportStatePassthrough,
34+
State: resourceComputeGlobalAddressImport,
35+
},
36+
37+
Timeouts: &schema.ResourceTimeout{
38+
Create: schema.DefaultTimeout(240 * time.Second),
39+
Delete: schema.DefaultTimeout(240 * time.Second),
2040
},
2141

2242
Schema: map[string]*schema.Schema{
23-
"name": &schema.Schema{
43+
"name": {
2444
Type: schema.TypeString,
2545
Required: true,
2646
ForceNew: true,
2747
},
28-
29-
"ip_version": &schema.Schema{
48+
"description": {
49+
Type: schema.TypeString,
50+
Optional: true,
51+
ForceNew: true,
52+
},
53+
"ip_version": {
3054
Type: schema.TypeString,
3155
Optional: true,
3256
ForceNew: true,
33-
ValidateFunc: validation.StringInSlice([]string{"IPV4", "IPV6", ""}, false),
57+
ValidateFunc: validation.StringInSlice([]string{"IPV4", "IPV6"}, false),
3458
},
35-
36-
"project": &schema.Schema{
59+
"address": {
3760
Type: schema.TypeString,
38-
Optional: true,
3961
Computed: true,
40-
ForceNew: true,
4162
},
42-
43-
"address": &schema.Schema{
63+
"creation_timestamp": {
4464
Type: schema.TypeString,
4565
Computed: true,
4666
},
47-
48-
"self_link": &schema.Schema{
67+
"project": {
4968
Type: schema.TypeString,
69+
Optional: true,
5070
Computed: true,
71+
ForceNew: true,
5172
},
5273
},
5374
}
@@ -61,25 +82,59 @@ func resourceComputeGlobalAddressCreate(d *schema.ResourceData, meta interface{}
6182
return err
6283
}
6384

64-
// Build the address parameter
65-
addr := &compute.Address{
66-
Name: d.Get("name").(string),
67-
IpVersion: d.Get("ip_version").(string),
85+
descriptionProp, err := expandComputeGlobalAddressDescription(d.Get("description"), d, config)
86+
if err != nil {
87+
return err
88+
}
89+
nameProp, err := expandComputeGlobalAddressName(d.Get("name"), d, config)
90+
if err != nil {
91+
return err
92+
}
93+
ipVersionProp, err := expandComputeGlobalAddressIpVersion(d.Get("ip_version"), d, config)
94+
if err != nil {
95+
return err
96+
}
97+
98+
obj := map[string]interface{}{
99+
"description": descriptionProp,
100+
"name": nameProp,
101+
"ipVersion": ipVersionProp,
68102
}
69103

70-
op, err := config.clientCompute.GlobalAddresses.Insert(project, addr).Do()
104+
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses")
71105
if err != nil {
72-
return fmt.Errorf("Error creating address: %s", err)
106+
return err
73107
}
74108

75-
// It probably maybe worked, so store the ID now
76-
d.SetId(addr.Name)
109+
log.Printf("[DEBUG] Creating new GlobalAddress: %#v", obj)
110+
res, err := Post(config, url, obj)
111+
if err != nil {
112+
return fmt.Errorf("Error creating GlobalAddress: %s", err)
113+
}
77114

78-
err = computeSharedOperationWait(config.clientCompute, op, project, "Creating Global Address")
115+
// Store the ID now
116+
id, err := replaceVars(d, config, "{{name}}")
117+
if err != nil {
118+
return fmt.Errorf("Error constructing id: %s", err)
119+
}
120+
d.SetId(id)
121+
122+
op := &compute.Operation{}
123+
err = Convert(res, op)
79124
if err != nil {
80125
return err
81126
}
82127

128+
waitErr := computeOperationWaitTime(
129+
config.clientCompute, op, project, "Creating GlobalAddress",
130+
int(d.Timeout(schema.TimeoutCreate).Minutes()))
131+
132+
if waitErr != nil {
133+
// The resource didn't actually create
134+
d.SetId("")
135+
return waitErr
136+
}
137+
83138
return resourceComputeGlobalAddressRead(d, meta)
84139
}
85140

@@ -91,16 +146,23 @@ func resourceComputeGlobalAddressRead(d *schema.ResourceData, meta interface{})
91146
return err
92147
}
93148

94-
addr, err := config.clientCompute.GlobalAddresses.Get(project, d.Id()).Do()
149+
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses/{{name}}")
95150
if err != nil {
96-
return handleNotFoundError(err, d, fmt.Sprintf("Global Address %q", d.Get("name").(string)))
151+
return err
97152
}
98153

99-
d.Set("name", addr.Name)
100-
d.Set("ip_version", addr.IpVersion)
101-
d.Set("address", addr.Address)
154+
res, err := Get(config, url)
155+
if err != nil {
156+
return handleNotFoundError(err, d, fmt.Sprintf("ComputeGlobalAddress %q", d.Id()))
157+
}
158+
159+
d.Set("address", flattenComputeGlobalAddressAddress(res["address"]))
160+
d.Set("creation_timestamp", flattenComputeGlobalAddressCreationTimestamp(res["creationTimestamp"]))
161+
d.Set("description", flattenComputeGlobalAddressDescription(res["description"]))
162+
d.Set("name", flattenComputeGlobalAddressName(res["name"]))
163+
d.Set("ip_version", flattenComputeGlobalAddressIpVersion(res["ipVersion"]))
164+
d.Set("self_link", res["selfLink"])
102165
d.Set("project", project)
103-
d.Set("self_link", ConvertSelfLinkToV1(addr.SelfLink))
104166

105167
return nil
106168
}
@@ -113,18 +175,76 @@ func resourceComputeGlobalAddressDelete(d *schema.ResourceData, meta interface{}
113175
return err
114176
}
115177

116-
// Delete the address
117-
log.Printf("[DEBUG] address delete request")
118-
op, err := config.clientCompute.GlobalAddresses.Delete(project, d.Id()).Do()
178+
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses/{{name}}")
179+
if err != nil {
180+
return err
181+
}
182+
183+
log.Printf("[DEBUG] Deleting GlobalAddress %q", d.Id())
184+
res, err := Delete(config, url)
185+
if err != nil {
186+
return fmt.Errorf("Error deleting GlobalAddress %q: %s", d.Id(), err)
187+
}
188+
189+
op := &compute.Operation{}
190+
err = Convert(res, op)
119191
if err != nil {
120-
return fmt.Errorf("Error deleting address: %s", err)
192+
return err
121193
}
122194

123-
err = computeSharedOperationWait(config.clientCompute, op, project, "Deleting Global Address")
195+
err = computeOperationWaitTime(
196+
config.clientCompute, op, project, "Deleting GlobalAddress",
197+
int(d.Timeout(schema.TimeoutDelete).Minutes()))
198+
124199
if err != nil {
125200
return err
126201
}
127202

128-
d.SetId("")
129203
return nil
130204
}
205+
206+
func resourceComputeGlobalAddressImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
207+
config := meta.(*Config)
208+
parseImportId([]string{"projects/(?P<project>[^/]+)/global/addresses/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
209+
210+
// Replace import id for the resource id
211+
id, err := replaceVars(d, config, "{{name}}")
212+
if err != nil {
213+
return nil, fmt.Errorf("Error constructing id: %s", err)
214+
}
215+
d.SetId(id)
216+
217+
return []*schema.ResourceData{d}, nil
218+
}
219+
220+
func flattenComputeGlobalAddressAddress(v interface{}) interface{} {
221+
return v
222+
}
223+
224+
func flattenComputeGlobalAddressCreationTimestamp(v interface{}) interface{} {
225+
return v
226+
}
227+
228+
func flattenComputeGlobalAddressDescription(v interface{}) interface{} {
229+
return v
230+
}
231+
232+
func flattenComputeGlobalAddressName(v interface{}) interface{} {
233+
return v
234+
}
235+
236+
func flattenComputeGlobalAddressIpVersion(v interface{}) interface{} {
237+
return v
238+
}
239+
240+
func expandComputeGlobalAddressDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
241+
return v, nil
242+
}
243+
244+
func expandComputeGlobalAddressName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
245+
return v, nil
246+
}
247+
248+
func expandComputeGlobalAddressIpVersion(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
249+
return v, nil
250+
}

google/resource_compute_global_address_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ func testAccComputeGlobalAddress_basic() string {
144144
return fmt.Sprintf(`
145145
resource "google_compute_global_address" "foobar" {
146146
name = "address-test-%s"
147+
description = "Created for Terraform acceptance testing"
147148
}`, acctest.RandString(10))
148149
}
149150

150151
func testAccComputeGlobalAddress_ipv6() string {
151152
return fmt.Sprintf(`
152153
resource "google_compute_global_address" "foobar" {
153154
name = "address-test-%s"
155+
description = "Created for Terraform acceptance testing"
154156
ip_version = "IPV6"
155157
}`, acctest.RandString(10))
156158
}

google/resource_compute_target_ssl_proxy.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/hashicorp/terraform/helper/schema"
24+
"github.com/hashicorp/terraform/helper/validation"
2425
compute "google.golang.org/api/compute/v1"
2526
)
2627

@@ -67,9 +68,10 @@ func resourceComputeTargetSslProxy() *schema.Resource {
6768
ForceNew: true,
6869
},
6970
"proxy_header": {
70-
Type: schema.TypeString,
71-
Optional: true,
72-
Default: "NONE",
71+
Type: schema.TypeString,
72+
Optional: true,
73+
ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1"}, false),
74+
Default: "NONE",
7375
},
7476
"creation_timestamp": {
7577
Type: schema.TypeString,

0 commit comments

Comments
 (0)