Instance (AWS)

May 6, 2026 · View on GitHub

AWS Instance with multiple SSH Key support.

Usage

ssh-keygen -t rsa
module "bastion" {
  source = "github.com/opszero/terraform-aws-bastion"

  ssh_keys = [ "ssh-rsa ..." ]
  
  users = {
    "username" = {
      ssh-keys = [
         "ssh-rs ..."
      ]
    }
  }
}

Connect

  • Use MrMgr to setup IAM access to the Bastion
  • pip3 install pip3 install ec2instanceconnectcli
  • mssh --profile awsprofile ubuntu@i-1234566

Deployment

terraform init
terraform plan
terraform apply -auto-approve

Teardown

terraform destroy -auto-approve

Providers

NameVersion
awsn/a
cloudinitn/a

Inputs

NameDescriptionTypeDefaultRequired
ami_idThe AMI ID of the bastion hoststringnullno
efs_mountsEFS multiple mountsmap{}no
ingress_cidrsConfiguration block for ingress rulesanyn/ayes
instance_profilen/a
object({
role_name = string
assume_role_service = string
policy_arns = list(string)
})
nullno
instance_typeEC2 Instance Type of the bastion hoststring"t3.micro"no
nameThe name of the bastion hoststringn/ayes
security_group_idsA list of security group names to associate with.list(any)[]no
ssh_keysSSH public keys to add to the imagelist(any)[]no
subnet_idThe VPC subnet ID to launch in EC2 bastion hoststringn/ayes
tagsA map of tags to assign to the resourcemap(any){}no
ubuntu_versionUbuntu Server Versionstring"24.04"no
user_dataUser data to provide when launching the instancestring""no
user_data_replace_on_changeTo recreate the instance when user_data is changedboolfalseno
userdataUser data to provide when launching the instancestring""no
usersCustom user accounts of the instancemap
{
"retool": {
"ssh-keys": []
}
}
no
volume_sizeSize of the volume in gibibytes (GiB)number20no
vpc_idThe VPC ID to create security group for bastion hoststringn/ayes

Resources

NameType
aws_cloudwatch_metric_alarm.aws_bastion_cpu_thresholdresource
aws_eip.thisresource
aws_iam_instance_profile.thisresource
aws_iam_role.thisresource
aws_iam_role_policy_attachment.thisresource
aws_instance.thisresource
aws_security_group.thisresource
aws_security_group_rule.thisresource
aws_ssm_parameter.ubuntudata source
cloudinit_config.configdata source

Outputs

NameDescription
instance_idn/a
public_ipn/a

🚀 Built by opsZero!

opsZero provides software and consulting for DevOps. With our decade plus of experience scaling some of the world’s most innovative companies we have developed deep expertise in Kubernetes, DevOps, FinOps, and Compliance.

Our software and consulting solutions enable organizations to:

  • migrate workloads to the Cloud
  • setup compliance frameworks including SOC2, HIPAA, PCI-DSS, ITAR, FedRamp, CMMC, and more.
  • FinOps solutions to reduce the cost of running Cloud workloads
  • Kubernetes optimized for web scale and AI workloads
  • finding underutilized Cloud resources
  • setting up custom AI training and delivery
  • building data integrations and scrapers
  • modernizing onto modern ARM based processors

We do this with a high-touch support model where you:

  • Get access to us on Slack, Microsoft Teams or Email
  • Get 24/7 coverage of your infrastructure
  • Get an accelerated migration to Kubernetes

Please schedule a call if you need support.



AWS Advanced Tier AWS DevOps Competency AWS EKS Delivery AWS Public Sector