Improve config - #4
Open
ravikiranvm wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Terraform configuration to improve portability and security around S3 buckets/state management and to make the WireGuard EC2 bootstrap/config outputs more usable.
Changes:
- Make the client-config S3 bucket name account-unique and add default encryption + public access blocking.
- Pass the S3 bucket name into EC2 user-data via
templatefile, add new root/module outputs (bucket name/ARN, VPN public IP), and select the latest Ubuntu 22.04 AMI dynamically. - Adjust networking/security posture by removing SSH ingress from the security group.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| terraform/outputs.tf | Adds outputs for bucket name/ARN and VPN public IP. |
| terraform/main.tf | Wires storage bucket name into compute module and updates backend bucket configuration. |
| terraform/modules/storage/main.tf | Makes bucket name account-specific and adds SSE + public access block; exports bucket name. |
| terraform/modules/security_group/main.tf | Removes SSH ingress rule (leaves WireGuard UDP ingress). |
| terraform/modules/compute/main.tf | Switches to dynamic Ubuntu AMI lookup; templates user-data with bucket name; tags instance. |
| terraform/modules/compute/variables.tf | Adds bucket_name input variable for user-data templating. |
| terraform/modules/compute/user_data.sh | Improves bootstrap logic (deps install, IMDSv2 public IP, dynamic iface); uploads client config to the bucket. |
| terraform_state/main.tf | Makes tfstate bucket name account-specific; adds provider + caller identity. |
| terraform_state/.terraform.lock.hcl | Adds provider lock file for the terraform_state root module. |
Files not reviewed (1)
- terraform_state/.terraform.lock.hcl: Generated file
Comments suppressed due to low confidence (1)
terraform/main.tf:57
- The backend S3 bucket is hard-coded to a specific AWS account ID, while
terraform_state/main.tfprovisionscloudvpn-tfstate-${account_id}. This makes the repo non-portable and easy to misconfigure for other accounts/environments. Consider using a partial backend configuration here and pass the bucket name viaterraform init -backend-config=..., or document a placeholder value instead of committing a real account-specific bucket name.
terraform {
backend "s3" {
bucket = "cloudvpn-tfstate-548846591939"
key = "CloudVPN/terraform.tfstate"
region = "ap-southeast-1"
encrypt = true
use_lockfile = true
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,63 +1,84 @@ | |||
| #!/bin/bash | |||
| set -eux | |||
Comment on lines
+43
to
+48
| PostUp = iptables -t nat -A POSTROUTING -o $PRIMARY_IFACE -j MASQUERADE | ||
| PostUp = iptables -A FORWARD -i wg0 -j ACCEPT | ||
| PostUp = iptables -A FORWARD -o wg0 -j ACCEPT | ||
| PostDown = iptables -t nat -D POSTROUTING -o $PRIMARY_IFACE -j MASQUERADE | ||
| PostDown = iptables -D FORWARD -i wg0 -j ACCEPT | ||
| PostDown = iptables -D FORWARD -o wg0 -j ACCEPT |
Comment on lines
12
to
+15
| variable instance_profile_name { | ||
| description = "Instance profile to access s3" | ||
| type = string | ||
| } |
Comment on lines
19
to
33
| resource "aws_instance" "wireguard_instance" { | ||
| ami = "ami-047126e50991d067b" | ||
| ami = data.aws_ami.ubuntu.id | ||
| instance_type = "t2.micro" | ||
| subnet_id = var.subnet_id | ||
| key_name = "CloudVPNInstanceKey" | ||
| subnet_id = var.subnet_id | ||
|
|
||
| iam_instance_profile = var.instance_profile_name | ||
|
|
||
| #security_groups = [var.security_group_id] # security_groups is for classic ec2 and default vpc only | ||
|
|
||
| vpc_security_group_ids = [var.security_group_id] | ||
|
|
||
| associate_public_ip_address = true | ||
|
|
||
| # User Data (providing the port and endpoint dynamically) | ||
|
|
||
| user_data = file("${path.module}/user_data.sh") | ||
| user_data = templatefile("${path.module}/user_data.sh", { | ||
| bucket_name = var.bucket_name | ||
| }) | ||
|
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.