@@ -5,20 +5,17 @@ import { pascalCase } from 'pascal-case';
55import { getAccountId , Account } from '../utils/accounts' ;
66import { VpcProps , VpcStack , Vpc } from '../common/vpc' ;
77import { Limit } from '../utils/limits' ;
8- import { NestedStack } from '@aws-cdk/aws-cloudformation' ;
98import {
10- InterfaceEndpointConfig ,
119 PeeringConnectionConfig ,
1210 IamConfig ,
1311 IamConfigType ,
1412 IamPolicyConfigType ,
1513 VpcConfig ,
1614} from '@aws-accelerator/common-config' ;
17- import { InterfaceEndpoint } from '../common/interface-endpoints' ;
1815import { IamAssets } from '../common/iam-assets' ;
1916import { STS } from '@aws-accelerator/common/src/aws/sts' ;
2017import { S3 } from '@aws-accelerator/common/src/aws/s3' ;
21- import { createRoleName , createName } from '@aws-accelerator/cdk-accelerator/src/core/accelerator-name-generator' ;
18+ import { createRoleName } from '@aws-accelerator/cdk-accelerator/src/core/accelerator-name-generator' ;
2219import { CentralBucketOutput , LogBucketOutput } from '../deployments/defaults/outputs' ;
2320import * as budget from '../deployments/billing/budget' ;
2421import * as certificates from '../deployments/certificates' ;
@@ -34,10 +31,6 @@ import { getIamUserPasswordSecretValue } from '../deployments/iam';
3431import * as cwlCentralLoggingToS3 from '../deployments/central-services/central-logging-s3' ;
3532import * as vpcDeployment from '../deployments/vpc' ;
3633import * as transitGateway from '../deployments/transit-gateway' ;
37- import { DNS_LOGGING_LOG_GROUP_REGION } from '@aws-accelerator/common/src/util/constants' ;
38- import { LogGroup } from '@aws-accelerator/custom-resource-logs-log-group' ;
39- import { LogResourcePolicy } from '@aws-accelerator/custom-resource-logs-resource-policy' ;
40- import { IamRoleOutputFinder } from '@aws-accelerator/common-outputs/src/iam-role' ;
4134import * as centralEndpoints from '../deployments/central-endpoints' ;
4235import { VpcOutputFinder , VpcSubnetOutput } from '@aws-accelerator/common-outputs/src/vpc' ;
4336
@@ -197,8 +190,10 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
197190 } ;
198191
199192 const subscriptionCheckDone : string [ ] = [ ] ;
193+ const dnsLogGroupsAccountAndRegion : { [ accoutKey : string ] : boolean } = { } ;
200194 // Create all the VPCs for accounts and organizational units
201195 for ( const { ouKey, accountKey, vpcConfig, deployments } of acceleratorConfig . getVpcConfigs ( ) ) {
196+ let createPolicy = false ;
202197 if ( ! limiter . create ( accountKey , Limit . VpcPerRegion , vpcConfig . region ) ) {
203198 console . log (
204199 `Skipping VPC "${ vpcConfig . name } " deployment. Reached maximum VPCs per region for account "${ accountKey } " and region "${ vpcConfig . region } ` ,
@@ -272,6 +267,22 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
272267 vpcConfig,
273268 vpcId : vpc ! . id ,
274269 } ) ;
270+
271+ // Create DNS Query Logging Log Group
272+ if ( vpcConfig . zones && vpcConfig . zones . public . length > 0 ) {
273+ if ( ! dnsLogGroupsAccountAndRegion [ accountKey ] ) {
274+ createPolicy = true ;
275+ dnsLogGroupsAccountAndRegion [ accountKey ] = true ;
276+ }
277+ await centralEndpoints . createDnsQueryLogGroup ( {
278+ acceleratorPrefix : context . acceleratorPrefix ,
279+ accountKey,
280+ accountStacks,
281+ outputs,
282+ vpcConfig,
283+ createPolicy,
284+ } ) ;
285+ }
275286 }
276287
277288 // Create the firewall
@@ -471,57 +482,6 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
471482 outputs,
472483 } ) ;
473484
474- /**
475- * Code to create LogGroups required for DNS Logging
476- */
477- const globalOptionsConfig = acceleratorConfig [ 'global-options' ] ;
478- const zoneConfig = globalOptionsConfig . zones . find ( zc => zc . names ) ;
479- const zonesAccountKey = zoneConfig ?. account ! ;
480-
481- const zonesStack = accountStacks . getOrCreateAccountStack ( zonesAccountKey , DNS_LOGGING_LOG_GROUP_REGION ) ;
482- const logGroupLambdaRoleOutput = IamRoleOutputFinder . tryFindOneByName ( {
483- outputs,
484- accountKey : zonesAccountKey ,
485- roleKey : 'LogGroupRole' ,
486- } ) ;
487- if ( logGroupLambdaRoleOutput ) {
488- const logGroups =
489- zoneConfig ?. names ?. public . map ( phz => {
490- const logGroupName = centralEndpoints . createR53LogGroupName ( {
491- acceleratorPrefix : context . acceleratorPrefix ,
492- domain : phz ,
493- } ) ;
494- return new LogGroup ( zonesStack , `Route53HostedZoneLogGroup${ pascalCase ( phz ) } ` , {
495- logGroupName,
496- roleArn : logGroupLambdaRoleOutput . roleArn ,
497- } ) ;
498- } ) || [ ] ;
499-
500- if ( logGroups . length > 0 ) {
501- const wildcardLogGroupName = centralEndpoints . createR53LogGroupName ( {
502- acceleratorPrefix : context . acceleratorPrefix ,
503- domain : '*' ,
504- } ) ;
505-
506- // Allow r53 services to write to the log group
507- const logGroupPolicy = new LogResourcePolicy ( zonesStack , 'R53LogGroupPolicy' , {
508- policyName : createName ( {
509- name : 'query-logging-pol' ,
510- } ) ,
511- policyStatements : [
512- new iam . PolicyStatement ( {
513- actions : [ 'logs:CreateLogStream' , 'logs:PutLogEvents' ] ,
514- principals : [ new iam . ServicePrincipal ( 'route53.amazonaws.com' ) ] ,
515- resources : [ `arn:aws:logs:${ cdk . Aws . REGION } :${ cdk . Aws . ACCOUNT_ID } :log-group:${ wildcardLogGroupName } ` ] ,
516- } ) ,
517- ] ,
518- } ) ;
519- for ( const logGroup of logGroups ) {
520- logGroupPolicy . node . addDependency ( logGroup ) ;
521- }
522- }
523- }
524-
525485 /**
526486 * DisAssociate HostedZone to VPC
527487 * - On Adding of InterfaceEndpoint in local VPC whose use-central-endpoint: true and Endpoint also esists in Central VPC
0 commit comments