-
Notifications
You must be signed in to change notification settings - Fork 51
/
gateway.go
370 lines (324 loc) · 13.3 KB
/
gateway.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package apigateway
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// A consumable API that can be used by multiple Gateways.
//
// To get more information about Gateway, see:
//
// * [API documentation](https://cloud.google.com/api-gateway/docs/reference/rest/v1beta/projects.locations.apis)
// * How-to Guides
// * [Official Documentation](https://cloud.google.com/api-gateway/docs/quickstart)
//
// ## Example Usage
// ### Apigateway Gateway Basic
//
// ```go
// package main
//
// import (
// "encoding/base64"
// "io/ioutil"
//
// "github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/apigateway"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// )
//
// func filebase64OrPanic(path string) pulumi.StringPtrInput {
// if fileData, err := ioutil.ReadFile(path); err == nil {
// return pulumi.String(base64.StdEncoding.EncodeToString(fileData[:]))
// } else {
// panic(err.Error())
// }
// }
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// apiGwApi, err := apigateway.NewApi(ctx, "apiGwApi", &apigateway.ApiArgs{
// ApiId: pulumi.String("api-gw"),
// }, pulumi.Provider(google_beta))
// if err != nil {
// return err
// }
// apiGwApiConfig, err := apigateway.NewApiConfig(ctx, "apiGwApiConfig", &apigateway.ApiConfigArgs{
// Api: apiGwApi.ApiId,
// ApiConfigId: pulumi.String("config"),
// OpenapiDocuments: apigateway.ApiConfigOpenapiDocumentArray{
// &apigateway.ApiConfigOpenapiDocumentArgs{
// Document: &apigateway.ApiConfigOpenapiDocumentDocumentArgs{
// Path: pulumi.String("spec.yaml"),
// Contents: filebase64OrPanic("test-fixtures/apigateway/openapi.yaml"),
// },
// },
// },
// }, pulumi.Provider(google_beta))
// if err != nil {
// return err
// }
// _, err = apigateway.NewGateway(ctx, "apiGwGateway", &apigateway.GatewayArgs{
// ApiConfig: apiGwApiConfig.ID(),
// GatewayId: pulumi.String("api-gw"),
// }, pulumi.Provider(google_beta))
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
//
// ## Import
//
// Gateway can be imported using any of these accepted formats
//
// ```sh
// $ pulumi import gcp:apigateway/gateway:Gateway default projects/{{project}}/locations/{{region}}/gateways/{{gateway_id}}
// ```
//
// ```sh
// $ pulumi import gcp:apigateway/gateway:Gateway default {{project}}/{{region}}/{{gateway_id}}
// ```
//
// ```sh
// $ pulumi import gcp:apigateway/gateway:Gateway default {{region}}/{{gateway_id}}
// ```
//
// ```sh
// $ pulumi import gcp:apigateway/gateway:Gateway default {{gateway_id}}
// ```
type Gateway struct {
pulumi.CustomResourceState
// Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig}.
// When changing api configs please ensure the new config is a new resource and the lifecycle rule `createBeforeDestroy` is set.
ApiConfig pulumi.StringOutput `pulumi:"apiConfig"`
// The default API Gateway host name of the form {gatewayId}-{hash}.{region_code}.gateway.dev.
DefaultHostname pulumi.StringOutput `pulumi:"defaultHostname"`
// A user-visible name for the API.
DisplayName pulumi.StringOutput `pulumi:"displayName"`
// Identifier to assign to the Gateway. Must be unique within scope of the parent resource(project).
GatewayId pulumi.StringOutput `pulumi:"gatewayId"`
// Resource labels to represent user-provided metadata.
Labels pulumi.StringMapOutput `pulumi:"labels"`
// Resource name of the Gateway. Format: projects/{project}/locations/{region}/gateways/{gateway}
Name pulumi.StringOutput `pulumi:"name"`
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project pulumi.StringOutput `pulumi:"project"`
// The region of the gateway for the API.
Region pulumi.StringOutput `pulumi:"region"`
}
// NewGateway registers a new resource with the given unique name, arguments, and options.
func NewGateway(ctx *pulumi.Context,
name string, args *GatewayArgs, opts ...pulumi.ResourceOption) (*Gateway, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.ApiConfig == nil {
return nil, errors.New("invalid value for required argument 'ApiConfig'")
}
if args.GatewayId == nil {
return nil, errors.New("invalid value for required argument 'GatewayId'")
}
var resource Gateway
err := ctx.RegisterResource("gcp:apigateway/gateway:Gateway", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetGateway gets an existing Gateway resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetGateway(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *GatewayState, opts ...pulumi.ResourceOption) (*Gateway, error) {
var resource Gateway
err := ctx.ReadResource("gcp:apigateway/gateway:Gateway", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Gateway resources.
type gatewayState struct {
// Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig}.
// When changing api configs please ensure the new config is a new resource and the lifecycle rule `createBeforeDestroy` is set.
ApiConfig *string `pulumi:"apiConfig"`
// The default API Gateway host name of the form {gatewayId}-{hash}.{region_code}.gateway.dev.
DefaultHostname *string `pulumi:"defaultHostname"`
// A user-visible name for the API.
DisplayName *string `pulumi:"displayName"`
// Identifier to assign to the Gateway. Must be unique within scope of the parent resource(project).
GatewayId *string `pulumi:"gatewayId"`
// Resource labels to represent user-provided metadata.
Labels map[string]string `pulumi:"labels"`
// Resource name of the Gateway. Format: projects/{project}/locations/{region}/gateways/{gateway}
Name *string `pulumi:"name"`
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project *string `pulumi:"project"`
// The region of the gateway for the API.
Region *string `pulumi:"region"`
}
type GatewayState struct {
// Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig}.
// When changing api configs please ensure the new config is a new resource and the lifecycle rule `createBeforeDestroy` is set.
ApiConfig pulumi.StringPtrInput
// The default API Gateway host name of the form {gatewayId}-{hash}.{region_code}.gateway.dev.
DefaultHostname pulumi.StringPtrInput
// A user-visible name for the API.
DisplayName pulumi.StringPtrInput
// Identifier to assign to the Gateway. Must be unique within scope of the parent resource(project).
GatewayId pulumi.StringPtrInput
// Resource labels to represent user-provided metadata.
Labels pulumi.StringMapInput
// Resource name of the Gateway. Format: projects/{project}/locations/{region}/gateways/{gateway}
Name pulumi.StringPtrInput
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project pulumi.StringPtrInput
// The region of the gateway for the API.
Region pulumi.StringPtrInput
}
func (GatewayState) ElementType() reflect.Type {
return reflect.TypeOf((*gatewayState)(nil)).Elem()
}
type gatewayArgs struct {
// Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig}.
// When changing api configs please ensure the new config is a new resource and the lifecycle rule `createBeforeDestroy` is set.
ApiConfig string `pulumi:"apiConfig"`
// A user-visible name for the API.
DisplayName *string `pulumi:"displayName"`
// Identifier to assign to the Gateway. Must be unique within scope of the parent resource(project).
GatewayId string `pulumi:"gatewayId"`
// Resource labels to represent user-provided metadata.
Labels map[string]string `pulumi:"labels"`
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project *string `pulumi:"project"`
// The region of the gateway for the API.
Region *string `pulumi:"region"`
}
// The set of arguments for constructing a Gateway resource.
type GatewayArgs struct {
// Resource name of the API Config for this Gateway. Format: projects/{project}/locations/global/apis/{api}/configs/{apiConfig}.
// When changing api configs please ensure the new config is a new resource and the lifecycle rule `createBeforeDestroy` is set.
ApiConfig pulumi.StringInput
// A user-visible name for the API.
DisplayName pulumi.StringPtrInput
// Identifier to assign to the Gateway. Must be unique within scope of the parent resource(project).
GatewayId pulumi.StringInput
// Resource labels to represent user-provided metadata.
Labels pulumi.StringMapInput
// The ID of the project in which the resource belongs.
// If it is not provided, the provider project is used.
Project pulumi.StringPtrInput
// The region of the gateway for the API.
Region pulumi.StringPtrInput
}
func (GatewayArgs) ElementType() reflect.Type {
return reflect.TypeOf((*gatewayArgs)(nil)).Elem()
}
type GatewayInput interface {
pulumi.Input
ToGatewayOutput() GatewayOutput
ToGatewayOutputWithContext(ctx context.Context) GatewayOutput
}
func (*Gateway) ElementType() reflect.Type {
return reflect.TypeOf((**Gateway)(nil)).Elem()
}
func (i *Gateway) ToGatewayOutput() GatewayOutput {
return i.ToGatewayOutputWithContext(context.Background())
}
func (i *Gateway) ToGatewayOutputWithContext(ctx context.Context) GatewayOutput {
return pulumi.ToOutputWithContext(ctx, i).(GatewayOutput)
}
// GatewayArrayInput is an input type that accepts GatewayArray and GatewayArrayOutput values.
// You can construct a concrete instance of `GatewayArrayInput` via:
//
// GatewayArray{ GatewayArgs{...} }
type GatewayArrayInput interface {
pulumi.Input
ToGatewayArrayOutput() GatewayArrayOutput
ToGatewayArrayOutputWithContext(context.Context) GatewayArrayOutput
}
type GatewayArray []GatewayInput
func (GatewayArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Gateway)(nil)).Elem()
}
func (i GatewayArray) ToGatewayArrayOutput() GatewayArrayOutput {
return i.ToGatewayArrayOutputWithContext(context.Background())
}
func (i GatewayArray) ToGatewayArrayOutputWithContext(ctx context.Context) GatewayArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(GatewayArrayOutput)
}
// GatewayMapInput is an input type that accepts GatewayMap and GatewayMapOutput values.
// You can construct a concrete instance of `GatewayMapInput` via:
//
// GatewayMap{ "key": GatewayArgs{...} }
type GatewayMapInput interface {
pulumi.Input
ToGatewayMapOutput() GatewayMapOutput
ToGatewayMapOutputWithContext(context.Context) GatewayMapOutput
}
type GatewayMap map[string]GatewayInput
func (GatewayMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Gateway)(nil)).Elem()
}
func (i GatewayMap) ToGatewayMapOutput() GatewayMapOutput {
return i.ToGatewayMapOutputWithContext(context.Background())
}
func (i GatewayMap) ToGatewayMapOutputWithContext(ctx context.Context) GatewayMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(GatewayMapOutput)
}
type GatewayOutput struct{ *pulumi.OutputState }
func (GatewayOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Gateway)(nil)).Elem()
}
func (o GatewayOutput) ToGatewayOutput() GatewayOutput {
return o
}
func (o GatewayOutput) ToGatewayOutputWithContext(ctx context.Context) GatewayOutput {
return o
}
type GatewayArrayOutput struct{ *pulumi.OutputState }
func (GatewayArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Gateway)(nil)).Elem()
}
func (o GatewayArrayOutput) ToGatewayArrayOutput() GatewayArrayOutput {
return o
}
func (o GatewayArrayOutput) ToGatewayArrayOutputWithContext(ctx context.Context) GatewayArrayOutput {
return o
}
func (o GatewayArrayOutput) Index(i pulumi.IntInput) GatewayOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Gateway {
return vs[0].([]*Gateway)[vs[1].(int)]
}).(GatewayOutput)
}
type GatewayMapOutput struct{ *pulumi.OutputState }
func (GatewayMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Gateway)(nil)).Elem()
}
func (o GatewayMapOutput) ToGatewayMapOutput() GatewayMapOutput {
return o
}
func (o GatewayMapOutput) ToGatewayMapOutputWithContext(ctx context.Context) GatewayMapOutput {
return o
}
func (o GatewayMapOutput) MapIndex(k pulumi.StringInput) GatewayOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Gateway {
return vs[0].(map[string]*Gateway)[vs[1].(string)]
}).(GatewayOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*GatewayInput)(nil)).Elem(), &Gateway{})
pulumi.RegisterInputType(reflect.TypeOf((*GatewayArrayInput)(nil)).Elem(), GatewayArray{})
pulumi.RegisterInputType(reflect.TypeOf((*GatewayMapInput)(nil)).Elem(), GatewayMap{})
pulumi.RegisterOutputType(GatewayOutput{})
pulumi.RegisterOutputType(GatewayArrayOutput{})
pulumi.RegisterOutputType(GatewayMapOutput{})
}