From 2af53a3ccbfe9169184958637452acd96bb01694 Mon Sep 17 00:00:00 2001 From: vickytechkey Date: Thu, 6 Aug 2026 11:31:47 +0530 Subject: [PATCH] Configure stack to use pre-created static Elastic IP placeholders --- aws_cdk/lib/aws_cdk-stack.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/aws_cdk/lib/aws_cdk-stack.ts b/aws_cdk/lib/aws_cdk-stack.ts index a754592..46594b7 100644 --- a/aws_cdk/lib/aws_cdk-stack.ts +++ b/aws_cdk/lib/aws_cdk-stack.ts @@ -69,19 +69,17 @@ export class AwsCdkStack extends cdk.Stack { 'apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin', 'systemctl enable docker', 'systemctl start docker', - // Setup wireguard directory and fetch Elastic IP dynamically using IMDSv2 + // Setup wireguard directory 'mkdir -p /home/ubuntu/wireguard', 'cd /home/ubuntu/wireguard', - 'TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")', - 'PUBLIC_IP=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4)', - // Write the docker-compose.yml file substituting the resolved public Elastic IP + // Write the docker-compose.yml file with hardcoded Elastic IP 'cat < docker-compose.yml', 'services:', ' wg-easy:', ' image: weejewel/wg-easy', ' container_name: wg-easy', ' environment:', - ' - WG_HOST=${PUBLIC_IP}', + ' - WG_HOST=YOUR_ELASTIC_IP_HERE', // <--- Replace with your manually created Elastic IP ' - PASSWORD=admin123', ' volumes:', ' - ./config:/etc/wireguard', @@ -101,22 +99,18 @@ export class AwsCdkStack extends cdk.Stack { 'chown -R ubuntu:ubuntu /home/ubuntu/wireguard' ); - - // 5. Provision Elastic IP and Associate with EC2 - const eip = new ec2.CfnEIP(this, 'MailServerEIP', { - domain: 'vpc', - }); - + // 5. Associate your pre-created Elastic IP using its Allocation ID new ec2.CfnEIPAssociation(this, 'MailServerEIPAssociation', { - allocationId: eip.attrAllocationId, + allocationId: 'YOUR_ALLOCATION_ID_HERE', // <--- Replace with your Elastic IP Allocation ID (e.g., eipalloc-xxxx) instanceId: instance.instanceId, }); // Outputs new cdk.CfnOutput(this, 'MailServerPublicIP', { - value: eip.ref, + value: 'YOUR_ELASTIC_IP_HERE', // <--- Replace with your Elastic IP description: 'The Elastic IP address of your Mail Server', }); } } +