@@ -5,9 +5,11 @@ import (
5
5
"context"
6
6
"encoding/json"
7
7
"fmt"
8
+ "math/rand"
8
9
"os"
9
10
"os/exec"
10
11
"path/filepath"
12
+ "strconv"
11
13
"strings"
12
14
"testing"
13
15
@@ -305,6 +307,72 @@ func TestAwsLambdaModuleIntegration(t *testing.T) {
305
307
})
306
308
}
307
309
310
+ // TODO: Ensure Delete truly deletes from the cloud https://github.com/pulumi/pulumi-terraform-module/issues/119
311
+
312
+ func TestIntegration (t * testing.T ) {
313
+
314
+ type testCase struct {
315
+ name string // Must be same as project folder in testdata/programs/ts
316
+ moduleName string
317
+ moduleVersion string
318
+ moduleNamespace string
319
+ previewExpect map [apitype.OpType ]int
320
+ upExpect map [string ]int
321
+ deleteExpect map [string ]int
322
+ }
323
+
324
+ testcases := []testCase {
325
+ {
326
+ name : "s3bucketmod" ,
327
+ moduleName : "terraform-aws-modules/s3-bucket/aws" ,
328
+ moduleVersion : "4.5.0" ,
329
+ moduleNamespace : "bucket" ,
330
+ previewExpect : map [apitype.OpType ]int {
331
+ apitype .OpType ("create" ): 5 ,
332
+ },
333
+ upExpect : map [string ]int {
334
+ "create" : 8 ,
335
+ },
336
+ deleteExpect : map [string ]int {
337
+ "delete" : 8 ,
338
+ },
339
+ },
340
+ }
341
+
342
+ for _ , tc := range testcases {
343
+ tc := tc
344
+ localProviderBinPath := ensureCompiledProvider (t )
345
+ skipLocalRunsWithoutCreds (t )
346
+ t .Run (tc .name , func (t * testing.T ) {
347
+ testProgram := filepath .Join ("testdata" , "programs" , "ts" , tc .name )
348
+ localPath := opttest .LocalProviderPath ("terraform-module" , filepath .Dir (localProviderBinPath ))
349
+ integrationTest := pulumitest .NewPulumiTest (t , testProgram , localPath )
350
+
351
+ prefix := generateTestResourcePrefix ()
352
+
353
+ // Get a prefix for resource names
354
+ integrationTest .SetConfig (t , "prefix" , prefix )
355
+
356
+ // Generate package
357
+ pulumiPackageAdd (t , integrationTest , localProviderBinPath , tc .moduleName , tc .moduleVersion , tc .moduleNamespace )
358
+
359
+ // Preview
360
+ previewResult := integrationTest .Preview (t )
361
+ autogold .Expect (tc .previewExpect ).Equal (t , previewResult .ChangeSummary )
362
+
363
+ // Up
364
+ upResult := integrationTest .Up (t )
365
+ autogold .Expect (& tc .upExpect ).Equal (t , upResult .Summary .ResourceChanges )
366
+
367
+ // Delete
368
+ destroyResult := integrationTest .Destroy (t )
369
+ autogold .Expect (& tc .deleteExpect ).Equal (t , destroyResult .Summary .ResourceChanges )
370
+
371
+ })
372
+ }
373
+
374
+ }
375
+
308
376
func getRoot (t * testing.T ) string {
309
377
wd , err := os .Getwd ()
310
378
require .NoError (t , err )
@@ -405,3 +473,12 @@ func pulumiPackageAdd(
405
473
require .NoError (t , err )
406
474
require .Equal (t , 0 , exitCode )
407
475
}
476
+
477
+ //nolint:gosec
478
+ func generateTestResourcePrefix () string {
479
+ low := 100000
480
+ high := 999999
481
+
482
+ num := low + rand .Intn (high - low )
483
+ return strconv .Itoa (num )
484
+ }
0 commit comments