Skip to content

[#327] Use AWS Session Manager to Securely connect to an EC2 instance#330

Open
tung-nimblehq wants to merge 4 commits intodevelopfrom
feature/327-add-ssm-login-instead-of-key-pair
Open

[#327] Use AWS Session Manager to Securely connect to an EC2 instance#330
tung-nimblehq wants to merge 4 commits intodevelopfrom
feature/327-add-ssm-login-instead-of-key-pair

Conversation

@tung-nimblehq
Copy link
Copy Markdown
Contributor

What happened 👀

  • Add iam_role module.
  • Update bastion module to set iam_instance_profile to allow it to connect with SSM.
  • Remove bastion_ingress_ssh_nimble ingress rule.
  • Add bastion_egress_ssm egress rule.
  • Remove variable bastion_image_id to use amazon_linux_2023 that will ensure the SSM agent was already set up on the image instance.
  • Create SSMInstanceRole to attach AmazonSSMManagedInstanceCore to bastion instance allow to connect with SSM

Insight 📝

  • Create Iam_role module to allow us to reuse for case needs to create role or profile(ec2), that's easier to maintain and more readable than injecting inside bastion main.tf content.
  • Before, we had bastion_image_id, which was inconvenient for developer experience because we had to go to the AWS console or use the CLI to list bastion image IDs, which took time and wasn't very necessary for a bastion instance. Instead, we can force the bastion to use the optimized and recommended image instance from AWS, amazon_linux_2023. It also sets up the SSM agent for us.
  • Still keep logic creating key-pair, but its default does not create.
variable "key_name" {
  description = "The name of the key pair to use for the instance"
  type        = string
  default     = "" // Set empty to disable key pair
}
  • Some benefits of SSM login instead of a key pair
    • Eliminating SSH key pair management
    • Removing the need to expose port 22
    • Enabling centralized, IAM-based access control
    • Providing full auditing and session logging
    • Aligning with AWS best practices for EC2 access

Proof Of Work 📹

Able to connect bastion instance without keypair, without an open ssh port, and without set specific ip address for connection

Screen.Recording.2026-01-24.at.21.28.34.mov

@tung-nimblehq tung-nimblehq self-assigned this Jan 24, 2026
@tung-nimblehq tung-nimblehq added the type : feature New feature or request label Jan 24, 2026
@tung-nimblehq tung-nimblehq force-pushed the feature/327-add-ssm-login-instead-of-key-pair branch from fba02c0 to e7d7b67 Compare January 25, 2026 03:19
@tung-nimblehq tung-nimblehq changed the title [Feature] [#327] Use AWS Session Manager to Securely connect to an EC2 instance [#327] Use AWS Session Manager to Securely connect to an EC2 instance Feb 24, 2026
Copy link
Copy Markdown

@DustinDust DustinDust left a comment

Choose a reason for hiding this comment

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

Approved with optional minor comments 💯

Base automatically changed from fix/326-migrate-bastion-module-from-launch-configuration-to-launch-template to develop February 26, 2026 02:38
@tung-nimblehq tung-nimblehq force-pushed the feature/327-add-ssm-login-instead-of-key-pair branch from 86b88db to 2a5a922 Compare February 26, 2026 03:25
@tung-nimblehq tung-nimblehq force-pushed the feature/327-add-ssm-login-instead-of-key-pair branch from 2a5a922 to 91d120f Compare February 27, 2026 02:59
Copy link
Copy Markdown

@toby-thanathip toby-thanathip left a comment

Choose a reason for hiding this comment

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

I've scanned through it, but I'm not certified enough to approve this. 🙇

→ Totally new to this template and Terraform; But, good to get the idea. 👍

@tung-nimblehq tung-nimblehq force-pushed the feature/327-add-ssm-login-instead-of-key-pair branch from 81dd178 to b5d8760 Compare March 5, 2026 09:11
image_id = var.image_id
image_id = data.aws_ami.amazon_linux_2023.id
instance_type = var.instance_type
key_name = var.key_name
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since we're replacing SSH with SSM, can we remove this? 🙏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm removed in 90b3e99

@tung-nimblehq tung-nimblehq force-pushed the feature/327-add-ssm-login-instead-of-key-pair branch from b5d8760 to 90b3e99 Compare March 5, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type : feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants