Skip to content

Commit bee09f5

Browse files
committed
build: instead of external referenced vpc, create own dedicated only to the users-api
1 parent 212cca1 commit bee09f5

7 files changed

Lines changed: 40 additions & 35 deletions

File tree

VirtualFinland.UsersAPI.Deployment/Common/Models/StackSetup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ public record StackSetup
88
public bool IsProductionEnvironment;
99
public string Environment = default!;
1010
public string ProjectName = default!;
11-
public VpcSetup VpcSetup = default!;
1211
}

VirtualFinland.UsersAPI.Deployment/Common/Models/VpcSetup.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

VirtualFinland.UsersAPI.Deployment/Features/DatabaseMigratorLambda.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace VirtualFinland.UsersAPI.Deployment.Features;
1212

1313
class DatabaseMigratorLambda
1414
{
15-
public DatabaseMigratorLambda(Config config, StackSetup stackSetup, SecretsManager secretsManager)
15+
public DatabaseMigratorLambda(Config config, StackSetup stackSetup, VpcSetup vpcSetup, SecretsManager secretsManager)
1616
{
1717
// Lambda function
1818
var execRole = new Role($"{stackSetup.ProjectName}-DatabaseMigratorLambdaRole-{stackSetup.Environment}", new RoleArgs
@@ -76,14 +76,14 @@ public DatabaseMigratorLambda(Config config, StackSetup stackSetup, SecretsManag
7676

7777
var defaultSecurityGroup = Pulumi.Aws.Ec2.GetSecurityGroup.Invoke(new GetSecurityGroupInvokeArgs()
7878
{
79-
VpcId = stackSetup.VpcSetup.VpcId,
79+
VpcId = vpcSetup.VpcId,
8080
Name = "default"
8181
});
8282

8383
var functionVpcArgs = new FunctionVpcConfigArgs()
8484
{
8585
SecurityGroupIds = defaultSecurityGroup.Apply(o => $"{o.Id}"),
86-
SubnetIds = stackSetup.VpcSetup.PrivateSubnetIds
86+
SubnetIds = vpcSetup.PrivateSubnetIds
8787
};
8888

8989
var appArtifactPath = Environment.GetEnvironmentVariable("DB_MIGRATOR_ARTIFACT_PATH") ?? config.Require("dbMigratorArtifactPath");

VirtualFinland.UsersAPI.Deployment/Features/LambdaFunctionUrl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace VirtualFinland.UsersAPI.Deployment.Features;
1616
/// </summary>
1717
class LambdaFunctionUrl
1818
{
19-
public LambdaFunctionUrl(Config config, StackSetup stackSetup, SecretsManager secretsManager)
19+
public LambdaFunctionUrl(Config config, StackSetup stackSetup, VpcSetup vpcSetup, SecretsManager secretsManager)
2020
{
2121
// External references
2222
var codesetStackReference = new StackReference($"{Pulumi.Deployment.Instance.OrganizationName}/codesets/{stackSetup.Environment}");
@@ -84,14 +84,14 @@ public LambdaFunctionUrl(Config config, StackSetup stackSetup, SecretsManager se
8484

8585
var defaultSecurityGroup = Pulumi.Aws.Ec2.GetSecurityGroup.Invoke(new GetSecurityGroupInvokeArgs()
8686
{
87-
VpcId = stackSetup.VpcSetup.VpcId,
87+
VpcId = vpcSetup.VpcId,
8888
Name = "default"
8989
});
9090

9191
var functionVpcArgs = new FunctionVpcConfigArgs()
9292
{
9393
SecurityGroupIds = defaultSecurityGroup.Apply(o => $"{o.Id}"),
94-
SubnetIds = stackSetup.VpcSetup.PrivateSubnetIds
94+
SubnetIds = vpcSetup.PrivateSubnetIds
9595
};
9696

9797
var appArtifactPath = Environment.GetEnvironmentVariable("APPLICATION_ARTIFACT_PATH") ?? config.Require("appArtifactPath");

VirtualFinland.UsersAPI.Deployment/Features/PostgresDatabase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace VirtualFinland.UsersAPI.Deployment.Features;
1111
/// </summary>
1212
public class PostgresDatabase
1313
{
14-
public PostgresDatabase(Config config, StackSetup stackSetup)
14+
public PostgresDatabase(Config config, StackSetup stackSetup, VpcSetup vpcSetup)
1515
{
1616
var dbSubNetGroup = new Pulumi.Aws.Rds.SubnetGroup("dbsubnets", new()
1717
{
18-
SubnetIds = stackSetup.VpcSetup.PrivateSubnetIds,
18+
SubnetIds = vpcSetup.PrivateSubnetIds,
1919
});
2020

2121
var password = new RandomPassword("password", new()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Immutable;
2+
using Pulumi;
3+
using Pulumi.Awsx.Ec2;
4+
using Pulumi.Awsx.Ec2.Inputs;
5+
6+
namespace VirtualFinland.UsersAPI.Deployment.Common.Models;
7+
8+
public class VpcSetup
9+
{
10+
public VpcSetup(StackSetup stackSetup)
11+
{
12+
var vpc = new Vpc($"{stackSetup.ProjectName}-vf-vpc-{stackSetup.Environment}", new VpcArgs()
13+
{
14+
Tags = stackSetup.Tags,
15+
EnableDnsHostnames = true,
16+
NatGateways = new NatGatewayConfigurationArgs
17+
{
18+
Strategy = stackSetup.IsProductionEnvironment ? NatGatewayStrategy.OnePerAz : NatGatewayStrategy.Single
19+
}
20+
});
21+
22+
this.VpcId = vpc.VpcId;
23+
this.PrivateSubnetIds = vpc.PrivateSubnetIds;
24+
}
25+
26+
public Input<string>? VpcId = default!;
27+
public Output<ImmutableArray<string>> PrivateSubnetIds = default!;
28+
}

VirtualFinland.UsersAPI.Deployment/UsersAPIStack.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System.Collections.Generic;
2-
using System.Collections.Immutable;
3-
using System.Linq;
41
using Pulumi;
52
using VirtualFinland.UsersAPI.Deployment.Common;
63
using VirtualFinland.UsersAPI.Deployment.Common.Models;
@@ -17,11 +14,6 @@ public UsersApiStack()
1714
var environment = Pulumi.Deployment.Instance.StackName;
1815
var projectName = Pulumi.Deployment.Instance.ProjectName;
1916

20-
var infraStackReference = new StackReference($"{Pulumi.Deployment.Instance.OrganizationName}/{config.Require("infraStackReferenceName")}/{environment}");
21-
var infraStackReferencePrivateSubnetIds = infraStackReference.RequireOutput("PrivateSubnetIds");
22-
var infraStackReferencePrivateSubnetIdsAsList = infraStackReferencePrivateSubnetIds.Apply(o => ((ImmutableArray<object>)(o ?? new ImmutableArray<object>())).Select(x => x.ToString()));
23-
var infraStackReferenceVpcId = infraStackReference.RequireOutput("VpcId");
24-
2517
InputMap<string> tags = new InputMap<string>()
2618
{
2719
{
@@ -38,22 +30,18 @@ public UsersApiStack()
3830
Environment = environment,
3931
IsProductionEnvironment = isProductionEnvironment,
4032
Tags = tags,
41-
VpcSetup = new VpcSetup()
42-
{
43-
VpcId = Output.Format($"{infraStackReferenceVpcId}"),
44-
PrivateSubnetIds = infraStackReferencePrivateSubnetIdsAsList as Output<IEnumerable<string>>
45-
}
4633
};
4734

48-
var dbConfigs = new PostgresDatabase(config, stackSetup);
35+
var vpcSetup = new VpcSetup(stackSetup);
36+
var dbConfigs = new PostgresDatabase(config, stackSetup, vpcSetup);
4937
var secretManagerSecret = new SecretsManager(config, stackSetup, dbConfigs);
5038

51-
var lambdaFunctionConfigs = new LambdaFunctionUrl(config, stackSetup, secretManagerSecret);
39+
var lambdaFunctionConfigs = new LambdaFunctionUrl(config, stackSetup, vpcSetup, secretManagerSecret);
5240
ApplicationUrl = lambdaFunctionConfigs.ApplicationUrl;
5341
LambdaId = lambdaFunctionConfigs.LambdaFunctionId;
5442
DBIdentifier = dbConfigs.DBIdentifier;
5543

56-
var databaseMigratorLambda = new DatabaseMigratorLambda(config, stackSetup, secretManagerSecret);
44+
var databaseMigratorLambda = new DatabaseMigratorLambda(config, stackSetup, vpcSetup, secretManagerSecret);
5745
DatabaseMigratorLambdaArn = databaseMigratorLambda.LambdaFunctionArn;
5846
}
5947

0 commit comments

Comments
 (0)