Skip to content
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

Refactor subnet creation #1521

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@boostercloud/framework-core",
"comment": "refactor subnet creation for Azure Provider",
"type": "minor"
}
],
"packageName": "@boostercloud/framework-core"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { TerraformNetworkSecurityGroup } from './gateway/terraform-network-secur
import { TerraformVirtualNetwork } from './gateway/terraform-virtual-network'
import { TerraformPublicIp } from './gateway/terraform-public-ip'
import { TerraformPublicIpData } from './gateway/terraform-public-ip-data'
import { TerraformSubnet } from './gateway/terraform-subnet'
import { TerraformSubnetSecurity } from './gateway/terraform-subnet-security'

export class ApplicationSynth {
readonly config: BoosterConfig
Expand Down Expand Up @@ -78,6 +80,8 @@ export class ApplicationSynth {
`${this.stackNames.resourceGroupName}rjsg`
)
stack.virtualNetwork = TerraformVirtualNetwork.build(stack)
stack.subnet = TerraformSubnet.build(stack)
stack.subnetNetworkSecurityGroupAssociation = TerraformSubnetSecurity.build(stack)
stack.publicIP = TerraformPublicIp.build(stack, 'pip')
stack.appGateway = TerraformApplicationGateway.build(stack)
stack.publicIPData = TerraformPublicIpData.build(stack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ export class TerraformApplicationGateway {
resourceGroupName,
functionAppName,
virtualNetwork,
subnet,
publicIP,
}: ApplicationSynthStack): applicationGateway.ApplicationGateway {
const environment = process.env.BOOSTER_ENV ?? 'azure'
if (!virtualNetwork) {
throw new Error('Undefined virtualNetwork resource')
}
if (!subnet) {
throw new Error('Undefined subnet resource')
}
if (!publicIP) {
throw new Error('Undefined publicIP resource')
}
Expand All @@ -36,7 +40,7 @@ export class TerraformApplicationGateway {
gatewayIpConfiguration: [
{
name: 'myGatewayIpConfiguration',
subnetId: virtualNetwork.subnet.get(0).id,
subnetId: subnet.id,
},
],
frontendIpConfiguration: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { toTerraformName } from '../../helper/utils'
import { ApplicationSynthStack } from '../../types/application-synth-stack'
import { subnetNetworkSecurityGroupAssociation } from '@cdktf/provider-azurerm'

export class TerraformSubnetSecurity {
static build({
terraformStack,
appPrefix,
networkSecurityGroup,
subnet,
}: ApplicationSynthStack): subnetNetworkSecurityGroupAssociation.SubnetNetworkSecurityGroupAssociation {
if (!networkSecurityGroup) {
throw new Error('Undefined networkSecurityGroup resource')
}
if (!subnet) {
throw new Error('Undefined subnet resource')
}

return new subnetNetworkSecurityGroupAssociation.SubnetNetworkSecurityGroupAssociation(
terraformStack,
toTerraformName(appPrefix, 'snsg'),
{
subnetId: subnet.id,
networkSecurityGroupId: networkSecurityGroup.id,
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { toTerraformName } from '../../helper/utils'
import { ApplicationSynthStack } from '../../types/application-synth-stack'
import { subnet } from '@cdktf/provider-azurerm'

export class TerraformSubnet {
static build({
terraformStack,
appPrefix,
virtualNetwork,
resourceGroupName,
networkSecurityGroup,
}: ApplicationSynthStack): subnet.Subnet {
if (!networkSecurityGroup) {
throw new Error('Undefined networkSecurityGroup resource')
}
if (!virtualNetwork) {
throw new Error('Undefined virtualNetwork resource')
}

return new subnet.Subnet(terraformStack, toTerraformName(appPrefix, 'vsn'), {
name: `${resourceGroupName}vsn`,
resourceGroupName: resourceGroupName,
virtualNetworkName: virtualNetwork.name,
addressPrefixes: ['10.0.1.0/24'],
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ export class TerraformVirtualNetwork {
location: resourceGroup.location,
resourceGroupName: resourceGroupName,
addressSpace: ['10.0.0.0/16'],
subnet: [
{
name: 'gatewaySubnet' + Math.floor(Math.random() * 100),
addressPrefix: '10.0.1.0/24',
securityGroup: networkSecurityGroup.id,
},
],
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
storageAccount,
virtualNetwork,
webPubsub,
subnet,
subnetNetworkSecurityGroupAssociation,
webPubsubHub,
windowsFunctionApp,
} from '@cdktf/provider-azurerm'
Expand Down Expand Up @@ -45,6 +47,8 @@ export interface ApplicationSynthStack extends StackNames {
dataFunctionAppHostKeys?: dataAzurermFunctionAppHostKeys.DataAzurermFunctionAppHostKeys
appGateway?: applicationGateway.ApplicationGateway
networkSecurityGroup?: networkSecurityGroup.NetworkSecurityGroup
subnet?: subnet.Subnet
subnetNetworkSecurityGroupAssociation?: subnetNetworkSecurityGroupAssociation.SubnetNetworkSecurityGroupAssociation
virtualNetwork?: virtualNetwork.VirtualNetwork
publicIP?: publicIp.PublicIp
publicIPData?: dataAzurermPublicIp.DataAzurermPublicIp
Expand Down
Loading