-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rds example test #219
Merged
Merged
Add rds example test #219
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e2871b1
try out outputs
corymhall 58e517e
fix formatting
corymhall ec8db2c
Add rds example test
corymhall 2ecdb10
fix test
corymhall 7f3b1a4
forgot missing dep
corymhall ca18e6c
fix examples
corymhall 3235acd
fix rebase
corymhall 0217556
moving examples
corymhall 929bdf6
fixing test
corymhall e91c6fb
Add readme to example
corymhall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: rds-example | ||
runtime: | ||
name: nodejs | ||
options: | ||
packagemanager: npm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as vpcmod from '@pulumi/vpcmod'; | ||
import * as pulumi from '@pulumi/pulumi'; | ||
import * as rdsmod from '@pulumi/rdsmod'; | ||
import * as aws from '@pulumi/aws'; | ||
import * as std from '@pulumi/std'; | ||
|
||
const azs = aws.getAvailabilityZonesOutput({ | ||
filters: [{ | ||
name: "opt-in-status", | ||
values: ["opt-in-not-required"], | ||
}] | ||
}).names.apply(names => names.slice(0, 3)); | ||
|
||
const cidr = "10.0.0.0/16"; | ||
|
||
const cfg = new pulumi.Config(); | ||
const prefix = cfg.get("prefix") ?? pulumi.getStack(); | ||
|
||
const vpc = new vpcmod.Module("test-vpc", { | ||
azs: azs, | ||
name: `test-vpc-${prefix}`, | ||
cidr, | ||
public_subnets: azs.apply(azs => azs.map((_, i) => { | ||
return getCidrSubnet(cidr, i+1); | ||
})), | ||
private_subnets: azs.apply(azs => azs.map((_, i) => { | ||
return getCidrSubnet(cidr, i+1+4); | ||
})), | ||
database_subnets: azs.apply(azs => azs.map((_, i) => { | ||
return getCidrSubnet(cidr, i+1 + 8); | ||
})), | ||
|
||
create_database_subnet_group: true, | ||
}); | ||
|
||
const rdsSecurityGroup = new aws.ec2.SecurityGroup('test-rds-sg', { | ||
vpcId: vpc.vpc_id.apply(id => id!), | ||
}); | ||
|
||
new aws.vpc.SecurityGroupIngressRule('test-rds-sg-ingress', { | ||
ipProtocol: 'tcp', | ||
securityGroupId: rdsSecurityGroup.id, | ||
cidrIpv4: vpc.vpc_cidr_block.apply(cidr => cidr!), | ||
fromPort: 3306, | ||
toPort: 3306, | ||
}); | ||
|
||
new rdsmod.Module("test-rds", { | ||
engine: "mysql", | ||
identifier: `test-rds-${prefix}`, | ||
manage_master_user_password: true, | ||
publicly_accessible: false, | ||
allocated_storage: 20, | ||
max_allocated_storage: 100, | ||
instance_class: "db.t4g.large", | ||
engine_version: "8.0", | ||
family: "mysql8.0", | ||
db_name: "completeMysql", | ||
username: "complete_mysql", | ||
port: '3306', | ||
multi_az: true, | ||
db_subnet_group_name: vpc.database_subnet_group_name.apply(name => name!), | ||
vpc_security_group_ids: [rdsSecurityGroup.id], | ||
skip_final_snapshot: true, | ||
deletion_protection: false, | ||
create_db_option_group: false, | ||
create_db_parameter_group: false, | ||
|
||
}) | ||
|
||
function getCidrSubnet(cidr: string, netnum: number): pulumi.Output<string> { | ||
return std.cidrsubnetOutput({ | ||
input: cidr, | ||
newbits: 8, | ||
netnum, | ||
}).result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "rds-example", | ||
"main": "index.ts", | ||
"devDependencies": { | ||
"@types/node": "^18", | ||
"typescript": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^6.72.0", | ||
"@pulumi/pulumi": "^3.113.0", | ||
"@pulumi/std": "^2.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pulumi/providertest/pulumitest" | ||
"github.com/pulumi/providertest/pulumitest/opttest" | ||
"github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy" | ||
"github.com/pulumi/pulumi/sdk/v3/go/auto/optpreview" | ||
"github.com/pulumi/pulumi/sdk/v3/go/auto/optup" | ||
) | ||
|
||
func Test_RdsExample(t *testing.T) { | ||
localProviderBinPath := ensureCompiledProvider(t) | ||
skipLocalRunsWithoutCreds(t) | ||
// Module written to support the test. | ||
testProgram, err := filepath.Abs(filepath.Join("../", "examples", "aws-rds-example")) | ||
require.NoError(t, err) | ||
localPath := opttest.LocalProviderPath("terraform-module", filepath.Dir(localProviderBinPath)) | ||
integrationTest := pulumitest.NewPulumiTest(t, testProgram, localPath) | ||
|
||
// Get a prefix for resource names | ||
prefix := generateTestResourcePrefix() | ||
|
||
// Set prefix via config | ||
integrationTest.SetConfig(t, "prefix", prefix) | ||
|
||
// Generate package | ||
pulumiPackageAdd(t, integrationTest, localProviderBinPath, "terraform-aws-modules/vpc/aws", "5.19.0", "vpcmod") | ||
pulumiPackageAdd(t, integrationTest, localProviderBinPath, "terraform-aws-modules/rds/aws", "6.10.0", "rdsmod") | ||
|
||
integrationTest.Up(t, optup.Diff(), | ||
optup.ErrorProgressStreams(os.Stderr), | ||
optup.ProgressStreams(os.Stdout), | ||
) | ||
|
||
stackName := integrationTest.CurrentStack().Name() | ||
projectSettings, err := integrationTest.CurrentStack().Workspace().ProjectSettings(context.Background()) | ||
assert.NoError(t, err) | ||
rdsUrn := fmt.Sprintf("urn:pulumi:%s::%s::rdsmod:index:Module::test-rds", stackName, projectSettings.Name.String()) | ||
|
||
integrationTest.Preview(t, optpreview.Diff(), optpreview.ExpectNoChanges(), | ||
optpreview.ErrorProgressStreams(os.Stderr), | ||
optpreview.ProgressStreams(os.Stdout), | ||
) | ||
|
||
// TODO [pulumi/pulumi-terraform-module#151] Property dependencies aren't flowing through | ||
integrationTest.Destroy(t, optdestroy.TargetDependents(), optdestroy.Target([]string{ | ||
rdsUrn, | ||
})) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a quick README and a script how to initialize this (pulumi package add). Since parameterized providers didn't make it into Pulumi.yaml yet this won't work OOTB.