Skip to content

Improve config - #4

Open
ravikiranvm wants to merge 2 commits into
mainfrom
update-conf
Open

Improve config#4
ravikiranvm wants to merge 2 commits into
mainfrom
update-conf

Conversation

@ravikiranvm

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.tf provisions cloudvpn-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 via terraform 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.

Comment thread terraform/modules/compute/user_data.sh Outdated
@@ -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
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants