Skip to content

Commit 831ca51

Browse files
Add preview "e2e" test for a basic RDS module
This uses the db.t4g.large but the test just crashes on the provisioning so that's fun Working preview
1 parent be8f1f3 commit 831ca51

File tree

4 files changed

+100
-8
lines changed

4 files changed

+100
-8
lines changed

tests/acc_test.go

+61-8
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ func TestS3BucketModSecret(t *testing.T) {
375375
"plaintext": "[{\"apply_server_side_encryption_by_default\":[{\"kms_master_key_id\":\"\",\"sse_algorithm\":\"AES256\"}]}]",
376376
}).Equal(t, encyptionsConfig.Inputs["rule"])
377377
integrationTest.Destroy(t)
378-
379378
}
380379

381380
// When writing out TF files, we need to replace data that is random with a static value
@@ -396,7 +395,7 @@ func cleanRandomDataFromTerraformArtifacts(t *testing.T, tfFilesDir string, repl
396395
s = strings.ReplaceAll(s, data, replace)
397396
}
398397

399-
err = os.WriteFile(path, []byte(s), 0600)
398+
err = os.WriteFile(path, []byte(s), 0o600)
400399
if err != nil {
401400
return err
402401
}
@@ -465,7 +464,6 @@ func TestS3BucketWithExplicitProvider(t *testing.T) {
465464
}
466465

467466
func TestIntegration(t *testing.T) {
468-
469467
type testCase struct {
470468
name string // Must be same as project folder in testdata/programs/ts
471469
moduleName string
@@ -510,7 +508,7 @@ func TestIntegration(t *testing.T) {
510508
deleteExpect: map[string]int{
511509
"delete": 9,
512510
},
513-
//TODO: [Fix delete-replace on null_resource](https://github.com/pulumi/pulumi-terraform-module/issues/166)
511+
// TODO: [Fix delete-replace on null_resource](https://github.com/pulumi/pulumi-terraform-module/issues/166)
514512
diffNoChangesExpect: map[apitype.OpType]int{
515513
apitype.OpType("replace"): 1,
516514
apitype.OpType("same"): 8,
@@ -556,6 +554,62 @@ func TestIntegration(t *testing.T) {
556554
}
557555
}
558556

557+
// Some resources take minutes to provision and destroy.
558+
// TestPreview is for such resources, where we only verify that preview works as expected.
559+
func TestPreview(t *testing.T) {
560+
type testCase struct {
561+
name string // Must be same as project folder in testdata/programs/ts
562+
moduleName string
563+
moduleVersion string
564+
moduleNamespace string
565+
previewExpect map[apitype.OpType]int
566+
}
567+
568+
testcases := []testCase{
569+
{
570+
name: "rdsmod",
571+
moduleName: "terraform-aws-modules/rds/aws",
572+
moduleVersion: "6.10.0",
573+
moduleNamespace: "rds",
574+
previewExpect: map[apitype.OpType]int{
575+
apitype.OpType("create"): 6,
576+
},
577+
},
578+
}
579+
580+
for _, tc := range testcases {
581+
tc := tc
582+
localProviderBinPath := ensureCompiledProvider(t)
583+
skipLocalRunsWithoutCreds(t)
584+
t.Run(tc.name, func(t *testing.T) {
585+
testProgram := filepath.Join("testdata", "programs", "ts", tc.name)
586+
localPath := opttest.LocalProviderPath("terraform-module", filepath.Dir(localProviderBinPath))
587+
previewTest := pulumitest.NewPulumiTest(t, testProgram, localPath)
588+
589+
// Get a prefix for resource names
590+
prefix := generateTestResourcePrefix()
591+
592+
// Set prefix via config
593+
previewTest.SetConfig(t, "prefix", prefix)
594+
595+
// Generate package
596+
pulumiPackageAdd(
597+
t,
598+
previewTest,
599+
localProviderBinPath,
600+
tc.moduleName,
601+
tc.moduleVersion,
602+
tc.moduleNamespace)
603+
604+
// Preview
605+
previewResult := previewTest.Preview(t)
606+
t.Log(previewResult.StdOut)
607+
t.Log(previewResult.StdErr)
608+
autogold.Expect(tc.previewExpect).Equal(t, previewResult.ChangeSummary)
609+
})
610+
}
611+
}
612+
559613
func TestDiffDetail(t *testing.T) {
560614
// Set up a test Bucket
561615
localProviderBinPath := ensureCompiledProvider(t)
@@ -577,16 +631,16 @@ func TestDiffDetail(t *testing.T) {
577631
// Up
578632
diffDetailTest.Up(t)
579633

580-
//Change program to remove the module input `server_side_encryption_configuration`
634+
// Change program to remove the module input `server_side_encryption_configuration`
581635
diffDetailTest.UpdateSource(t, filepath.Join("testdata", "programs", "ts", "s3bucketmod", "updates"))
582636

583637
// Preview
584638
previewResult := diffDetailTest.Preview(t, optpreview.Diff())
585639

586640
var providerID string
587641

588-
//Extract the provider URN from state
589-
//TODO: once explicit providers are
642+
// Extract the provider URN from state
643+
// TODO: once explicit providers are
590644
var state map[string]interface{}
591645
err := json.Unmarshal(diffDetailTest.ExportStack(t).Deployment, &state)
592646
if err != nil {
@@ -923,7 +977,6 @@ func TestDeleteLambda(t *testing.T) {
923977
} else {
924978
t.Fatalf("encountered unexpected error verifying log group was deleted: %v ", err)
925979
}
926-
927980
}
928981

929982
// runPreviewWithPlanDiff runs a pulumi preview that creates a plan file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: rdsmod
2+
runtime: nodejs
3+
description: A minimal TypeScript Pulumi program
4+
config:
5+
pulumi:tags:
6+
value:
7+
pulumi:template: typescript
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as pulumi from "@pulumi/pulumi";
2+
import * as rds from "@pulumi/rds";
3+
4+
5+
const testrds = new rds.Module("test-rds", {
6+
identifier: "test-rds-module",
7+
engine: "mysql",
8+
instance_class: "db.t3.micro",
9+
allocated_storage: 20,
10+
db_name: "testrdsmoduledatabase",
11+
username: "pulumipus",
12+
password: "hawaii",
13+
skip_final_snapshot: true,
14+
deletion_protection: false,
15+
16+
// DB parameter group
17+
family: "mysql8.0",
18+
19+
// DB option group
20+
major_engine_version: "8.0",
21+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "rdsmod",
3+
"devDependencies": {
4+
"@types/node": "^14"
5+
},
6+
"dependencies": {
7+
"@pulumi/pulumi": "^3.0.0",
8+
"@pulumi/terraform-aws-modules": "file:sdks/terraform-aws-modules",
9+
"typescript": "^4.0.0"
10+
}
11+
}

0 commit comments

Comments
 (0)