@@ -21,6 +21,7 @@ import (
21
21
"crypto/md5"
22
22
"encoding/hex"
23
23
"encoding/json"
24
+ "fmt"
24
25
"io/ioutil"
25
26
"os"
26
27
@@ -35,9 +36,10 @@ import (
35
36
"github.com/pulumi/pulumi/sdk/v3/go/auto"
36
37
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
37
38
38
- "github.com/nitrictech/cli/pkg/provider/pulumi/types "
39
+ "github.com/nitrictech/cli/pkg/provider/pulumi/common "
39
40
"github.com/nitrictech/cli/pkg/stack"
40
41
"github.com/nitrictech/cli/pkg/target"
42
+ "github.com/nitrictech/cli/pkg/utils"
41
43
v1 "github.com/nitrictech/nitric/pkg/api/nitric/v1"
42
44
)
43
45
@@ -47,31 +49,56 @@ type awsProvider struct {
47
49
tmpDir string
48
50
}
49
51
50
- func New (s * stack.Stack , t * target.Target ) types .PulumiProvider {
52
+ func New (s * stack.Stack , t * target.Target ) common .PulumiProvider {
51
53
return & awsProvider {s : s , t : t }
52
54
}
53
55
54
- func (a * awsProvider ) PluginName () string {
55
- return "aws"
56
+ func (a * awsProvider ) Plugins () []common.Plugin {
57
+ return []common.Plugin {
58
+ {
59
+ Name : "aws" ,
60
+ Version : "v4.37.1" ,
61
+ },
62
+ }
56
63
}
57
64
58
- func (a * awsProvider ) PluginVersion () string {
59
- return "v4.0.0"
65
+ func (a * awsProvider ) SupportedRegions () []string {
66
+ return []string {
67
+ "us-east-1" ,
68
+ "us-west-1" ,
69
+ "us-west-2" ,
70
+ "eu-west-1" ,
71
+ "eu-central-1" ,
72
+ "ap-southeast-1" ,
73
+ "ap-northeast-1" ,
74
+ "ap-southeast-2" ,
75
+ "ap-northeast-2" ,
76
+ "sa-east-1" ,
77
+ "cn-north-1" ,
78
+ "ap-south-1" ,
79
+ }
60
80
}
61
81
62
- func (a * awsProvider ) Configure (ctx context.Context , autoStack * auto.Stack ) error {
63
- if a .t .Region != "" {
64
- return autoStack .SetConfig (ctx , "aws:region" , auto.ConfigValue {Value : a .t .Region })
82
+ func (a * awsProvider ) Validate () error {
83
+ found := false
84
+ for _ , r := range a .SupportedRegions () {
85
+ if r == a .t .Region {
86
+ found = true
87
+ break
88
+ }
89
+ }
90
+ if ! found {
91
+ return utils .NewNotSupportedErr (fmt .Sprintf ("region %s not supported on provider %s" , a .t .Region , a .t .Provider ))
65
92
}
66
93
return nil
67
94
}
68
95
69
- func commonTags (ctx * pulumi.Context , name string ) pulumi.StringMap {
70
- return pulumi.StringMap {
71
- "x-nitric-project" : pulumi .String (ctx .Project ()),
72
- "x-nitric-stack" : pulumi .String (ctx .Stack ()),
73
- "x-nitric-name" : pulumi .String (name ),
96
+ func (a * awsProvider ) Configure (ctx context.Context , autoStack * auto.Stack ) error {
97
+ if a .t .Region != "" {
98
+ return autoStack .SetConfig (ctx , "aws:region" , auto.ConfigValue {Value : a .t .Region })
74
99
}
100
+
101
+ return nil
75
102
}
76
103
77
104
func md5Hash (b []byte ) string {
@@ -124,7 +151,7 @@ func (a *awsProvider) Deploy(ctx *pulumi.Context) error {
124
151
// FIXME: Autonaming of topics disabled until improvements to
125
152
// nitric topic name discovery is made for SNS topics.
126
153
Name : pulumi .StringPtr (k ),
127
- Tags : commonTags (ctx , k ),
154
+ Tags : common . Tags (ctx , k ),
128
155
})
129
156
if err != nil {
130
157
return errors .WithMessage (err , "sns topic " + k )
@@ -134,7 +161,7 @@ func (a *awsProvider) Deploy(ctx *pulumi.Context) error {
134
161
buckets := map [string ]* s3.Bucket {}
135
162
for k := range a .s .Buckets {
136
163
buckets [k ], err = s3 .NewBucket (ctx , k , & s3.BucketArgs {
137
- Tags : commonTags (ctx , k ),
164
+ Tags : common . Tags (ctx , k ),
138
165
})
139
166
if err != nil {
140
167
return errors .WithMessage (err , "s3 bucket " + k )
@@ -144,7 +171,7 @@ func (a *awsProvider) Deploy(ctx *pulumi.Context) error {
144
171
queues := map [string ]* sqs.Queue {}
145
172
for k := range a .s .Queues {
146
173
queues [k ], err = sqs .NewQueue (ctx , k , & sqs.QueueArgs {
147
- Tags : commonTags (ctx , k ),
174
+ Tags : common . Tags (ctx , k ),
148
175
})
149
176
if err != nil {
150
177
return errors .WithMessage (err , "sqs queue " + k )
@@ -167,7 +194,7 @@ func (a *awsProvider) Deploy(ctx *pulumi.Context) error {
167
194
HashKey : pulumi .String ("_pk" ),
168
195
RangeKey : pulumi .String ("_sk" ),
169
196
BillingMode : pulumi .String ("PAY_PER_REQUEST" ),
170
- Tags : commonTags (ctx , k ),
197
+ Tags : common . Tags (ctx , k ),
171
198
})
172
199
if err != nil {
173
200
return errors .WithMessage (err , "dynamodb table " + k )
@@ -191,46 +218,48 @@ func (a *awsProvider) Deploy(ctx *pulumi.Context) error {
191
218
funcs := map [string ]* Lambda {}
192
219
principalMap := make (map [v1.ResourceType ]map [string ]* iam.Role )
193
220
principalMap [v1 .ResourceType_Function ] = make (map [string ]* iam.Role )
194
- for k , f := range a .s .Functions {
195
- image , err := newECRImage (ctx , f .Name , & ECRImageArgs {
196
- LocalImageName : f .ImageTagName (a .s , "" ),
197
- SourceImageName : f .ImageTagName (a .s , a .t .Provider ),
198
- AuthToken : authToken ,
199
- TempDir : a .tmpDir })
200
- if err != nil {
201
- return errors .WithMessage (err , "function image tag " + f .Name )
202
- }
203
- funcs [k ], err = newLambda (ctx , k , & LambdaArgs {
204
- Topics : topics ,
205
- DockerImage : image .DockerImage ,
206
- Compute : & f ,
221
+
222
+ computes := []stack.Compute {}
223
+ for _ , c := range a .s .Functions {
224
+ copy := c
225
+ computes = append (computes , & copy )
226
+ }
227
+ for _ , c := range a .s .Containers {
228
+ copy := c
229
+ computes = append (computes , & copy )
230
+ }
231
+ for _ , c := range computes {
232
+ localImageName := c .ImageTagName (a .s , "" )
233
+
234
+ repo , err := ecr .NewRepository (ctx , localImageName , & ecr.RepositoryArgs {
235
+ Tags : common .Tags (ctx , localImageName ),
207
236
})
208
237
if err != nil {
209
- return errors . WithMessage ( err , "lambda function " + f . Name )
238
+ return err
210
239
}
211
240
212
- principalMap [v1.ResourceType_Function ][k ] = funcs [k ].Role
213
- }
214
-
215
- for k , c := range a .s .Containers {
216
- image , err := newECRImage (ctx , c .Name , & ECRImageArgs {
217
- LocalImageName : c .ImageTagName (a .s , "" ),
241
+ image , err := common .NewImage (ctx , c .Unit ().Name , & common.ImageArgs {
242
+ LocalImageName : localImageName ,
218
243
SourceImageName : c .ImageTagName (a .s , a .t .Provider ),
219
- AuthToken : authToken ,
244
+ RepositoryUrl : repo .RepositoryUrl ,
245
+ Server : pulumi .String (authToken .ProxyEndpoint ),
246
+ Username : pulumi .String (authToken .UserName ),
247
+ Password : pulumi .String (authToken .Password ),
220
248
TempDir : a .tmpDir })
221
249
if err != nil {
222
- return errors .WithMessage (err , "function image tag " + c .Name )
250
+ return errors .WithMessage (err , "function image tag " + c .Unit (). Name )
223
251
}
224
- funcs [k ], err = newLambda (ctx , k , & LambdaArgs {
252
+
253
+ funcs [c .Unit ().Name ], err = newLambda (ctx , c .Unit ().Name , & LambdaArgs {
225
254
Topics : topics ,
226
255
DockerImage : image .DockerImage ,
227
- Compute : & c ,
256
+ Compute : c ,
228
257
})
229
258
if err != nil {
230
- return errors .WithMessage (err , "lambda container " + c .Name )
259
+ return errors .WithMessage (err , "lambda container " + c .Unit (). Name )
231
260
}
232
261
233
- principalMap [v1.ResourceType_Function ][k ] = funcs [k ].Role
262
+ principalMap [v1 .ResourceType_Function ][c . Unit (). Name ] = funcs [c . Unit (). Name ].Role
234
263
}
235
264
236
265
for k , v := range a .s .ApiDocs {
@@ -244,7 +273,6 @@ func (a *awsProvider) Deploy(ctx *pulumi.Context) error {
244
273
245
274
for _ , p := range a .s .Policies {
246
275
policyName , err := policyResourceName (p )
247
-
248
276
if err != nil {
249
277
return err
250
278
}
0 commit comments