Giter Site home page Giter Site logo

cloudposse / terraform-aws-ec2-bastion-server Goto Github PK

View Code? Open in Web Editor NEW
149.0 19.0 108.0 2.3 MB

Terraform module to define a generic Bastion host with parameterized user_data and support for AWS SSM Session Manager for remote access with IAM authentication.

Home Page: https://cloudposse.com/accelerate

License: Apache License 2.0

HCL 73.82% Shell 7.02% Makefile 7.54% Go 11.62%
terraform terraform-modules aws bastion ssm ssh session-manager zerotrust beyondcorp jumpbox

terraform-aws-ec2-bastion-server's Introduction

Project Banner

Latest ReleaseLast UpdatedSlack Community

Terraform module to define a generic Bastion host with parameterized user_data and support for AWS SSM Session Manager for remote access with IAM authentication.

Tip

πŸ‘½ Use Atmos with Terraform

Cloud Posse uses atmos to easily orchestrate multiple environments using Terraform.
Works with Github Actions, Atlantis, or Spacelift.

Watch demo of using Atmos with Terraform
Example of running atmos to manage infrastructure from our Quick Start tutorial.

Makefile Targets

Available targets:

  help                                Help screen
  help/all                            Display help for all targets
  help/short                          This help short screen
  lint                                Lint terraform code

Requirements

Name Version
terraform >= 0.13.0
aws >= 2.55

Providers

Name Version
aws >= 2.55

Modules

Name Source Version
dns cloudposse/route53-cluster-hostname/aws 0.12.2
security_group cloudposse/security-group/aws 0.3.3
this cloudposse/label/null 0.25.0

Resources

Name Type
aws_eip.default resource
aws_iam_instance_profile.default resource
aws_iam_role.default resource
aws_iam_role_policy.main resource
aws_instance.default resource
aws_ami.default data source
aws_iam_policy_document.default data source
aws_iam_policy_document.main data source
aws_region.default data source
aws_route53_zone.domain data source

Inputs

Name Description Type Default Required
additional_tag_map Additional key-value pairs to add to each map in tags_as_list_of_maps. Not added to tags or id.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration.
map(string) {} no
ami AMI to use for the instance. Setting this will ignore ami_filter and ami_owners. string null no
ami_filter List of maps used to create the AMI filter for the action runner AMI. map(list(string))
{
"name": [
"amzn2-ami-hvm-2.*-x86_64-ebs"
]
}
no
ami_owners The list of owners used to select the AMI of action runner instances. list(string)
[
"amazon"
]
no
assign_eip_address Assign an Elastic IP address to the instance bool true no
associate_public_ip_address Whether to associate a public IP to the instance. bool false no
attributes ID element. Additional attributes (e.g. workers or cluster) to add to id,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the delimiter
and treated as a single ID element.
list(string) [] no
context Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as null to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
any
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
no
delimiter Delimiter to be used between ID elements.
Defaults to - (hyphen). Set to "" to use no delimiter at all.
string null no
descriptor_formats Describe additional descriptors to be output in the descriptors output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
{<br> format = string<br> labels = list(string)<br>}
(Type is any so the map values can later be enhanced to provide additional options.)
format is a Terraform format string to be passed to the format() function.
labels is a list of labels, in order, to pass to format() function.
Label values will be normalized before being passed to format() so they will be
identical to how they appear in id.
Default is {} (descriptors output will be empty).
any {} no
disable_api_termination Enable EC2 Instance Termination Protection bool false no
ebs_block_device_encrypted Whether to encrypt the EBS block device bool true no
ebs_block_device_volume_size The volume size (in GiB) to provision for the EBS block device. Creation skipped if size is 0 number 0 no
ebs_delete_on_termination Whether the EBS volume should be destroyed on instance termination bool true no
ebs_device_name The name of the EBS block device to mount on the instance string "/dev/sdh" no
enabled Set to false to prevent the module from creating any resources bool null no
environment ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' string null no
host_name The Bastion hostname created in Route53 string "bastion" no
id_length_limit Limit id to this many characters (minimum 6).
Set to 0 for unlimited length.
Set to null for keep the existing setting, which defaults to 0.
Does not affect id_full.
number null no
instance_profile A pre-defined profile to attach to the instance (default is to build our own) string "" no
instance_type Bastion instance type string "t2.micro" no
key_name Key name string "" no
label_key_case Controls the letter case of the tags keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the tags input.
Possible values: lower, title, upper.
Default value: title.
string null no
label_order The order in which the labels (ID elements) appear in the id.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
list(string) null no
label_value_case Controls the letter case of ID elements (labels) as included in id,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the tags input.
Possible values: lower, title, upper and none (no transformation).
Set this to title and set delimiter to "" to yield Pascal Case IDs.
Default value: lower.
string null no
labels_as_tags Set of labels (ID elements) to include as tags in the tags output.
Default is to include all labels.
Tags with empty values will not be included in the tags output.
Set to [] to suppress all generated tags.
Notes:
The value of the name tag, if included, will be the id, not the name.
Unlike other null-label inputs, the initial setting of labels_as_tags cannot be
changed in later chained modules. Attempts to change it will be silently ignored.
set(string)
[
"default"
]
no
metadata_http_endpoint_enabled Whether the metadata service is available bool true no
metadata_http_put_response_hop_limit The desired HTTP PUT response hop limit (between 1 and 64) for instance metadata requests. number 1 no
metadata_http_tokens_required Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2. bool true no
monitoring Launched EC2 instance will have detailed monitoring enabled bool true no
name ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a tag.
The "name" tag is set to the full id string. There is no tag with the value of the name input.
string null no
namespace ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique string null no
regex_replace_chars Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits.
string null no
root_block_device_encrypted Whether to encrypt the root block device bool true no
root_block_device_volume_size The volume size (in GiB) to provision for the root block device. It cannot be smaller than the AMI it refers to. number 8 no
security_group_description The Security Group description. string "Bastion host security group" no
security_group_enabled Whether to create default Security Group for bastion host. bool true no
security_group_rules A list of maps of Security Group rules.
The values of map is fully complated with aws_security_group_rule resource.
To get more info see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule .
list(any)
[
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "Allow all outbound traffic",
"from_port": 0,
"protocol": -1,
"to_port": 0,
"type": "egress"
},
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "Allow all inbound to SSH",
"from_port": 22,
"protocol": "tcp",
"to_port": 22,
"type": "ingress"
}
]
no
security_group_use_name_prefix Whether to create a default Security Group with unique name beginning with the normalized prefix. bool false no
security_groups A list of Security Group IDs to associate with bastion host. list(string) [] no
ssh_user Default SSH user for this AMI. e.g. ec2-user for Amazon Linux and ubuntu for Ubuntu systems string "ec2-user" no
ssm_enabled Enable SSM Agent on Host. bool true no
stage ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' string null no
subnets AWS subnet IDs list(string) n/a yes
tags Additional tags (e.g. {'BusinessUnit': 'XYZ'}).
Neither the tag keys nor the tag values will be modified by this module.
map(string) {} no
tenant ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for string null no
user_data User data content. Will be ignored if user_data_base64 is set list(string) [] no
user_data_base64 The Base64-encoded user data to provide when launching the instances. If this is set then user_data will not be used. string "" no
user_data_template User Data template to use for provisioning EC2 Bastion Host string "user_data/amazon-linux.sh" no
vpc_id VPC ID string n/a yes
zone_id Route53 DNS Zone ID string "" no

Outputs

Name Description
arn ARN of the instance
hostname DNS hostname
id Disambiguated ID of the instance
instance_id Instance ID
name Instance name
private_dns Private DNS of instance
private_ip Private IP of the instance
public_dns Public DNS of instance (or DNS of EIP)
public_ip Public IP of the instance (or EIP)
role Name of AWS IAM Role associated with the instance
security_group_arn Bastion host Security Group ARN
security_group_id Bastion host Security Group ID
security_group_ids IDs on the AWS Security Groups associated with the instance
security_group_name Bastion host Security Group name
ssh_user SSH user

Related Projects

Check out these related projects.

  • bastion - πŸ”’Secure Bastion implemented as Docker Container running Alpine Linux with Google Authenticator & DUO MFA support
  • terraform-aws-ec2-instance - Terraform module for providing a general EC2 instance provisioned by Ansible
  • terraform-aws-ec2-ami-backup - Terraform module for automatic & scheduled AMI creation

Tip

Use Terraform Reference Architectures for AWS

Use Cloud Posse's ready-to-go terraform architecture blueprints for AWS to get up and running quickly.

βœ… We build it together with your team.
βœ… Your team owns everything.
βœ… 100% Open Source and backed by fanatical support.

Request Quote

πŸ“š Learn More

Cloud Posse is the leading DevOps Accelerator for funded startups and enterprises.

Your team can operate like a pro today.

Ensure that your team succeeds by using Cloud Posse's proven process and turnkey blueprints. Plus, we stick around until you succeed.

Day-0: Your Foundation for Success

  • Reference Architecture. You'll get everything you need from the ground up built using 100% infrastructure as code.
  • Deployment Strategy. Adopt a proven deployment strategy with GitHub Actions, enabling automated, repeatable, and reliable software releases.
  • Site Reliability Engineering. Gain total visibility into your applications and services with Datadog, ensuring high availability and performance.
  • Security Baseline. Establish a secure environment from the start, with built-in governance, accountability, and comprehensive audit logs, safeguarding your operations.
  • GitOps. Empower your team to manage infrastructure changes confidently and efficiently through Pull Requests, leveraging the full power of GitHub Actions.

Request Quote

Day-2: Your Operational Mastery

  • Training. Equip your team with the knowledge and skills to confidently manage the infrastructure, ensuring long-term success and self-sufficiency.
  • Support. Benefit from a seamless communication over Slack with our experts, ensuring you have the support you need, whenever you need it.
  • Troubleshooting. Access expert assistance to quickly resolve any operational challenges, minimizing downtime and maintaining business continuity.
  • Code Reviews. Enhance your team’s code quality with our expert feedback, fostering continuous improvement and collaboration.
  • Bug Fixes. Rely on our team to troubleshoot and resolve any issues, ensuring your systems run smoothly.
  • Migration Assistance. Accelerate your migration process with our dedicated support, minimizing disruption and speeding up time-to-value.
  • Customer Workshops. Engage with our team in weekly workshops, gaining insights and strategies to continuously improve and innovate.

Request Quote

✨ Contributing

This project is under active development, and we encourage contributions from our community.

Many thanks to our outstanding contributors:

For πŸ› bug reports & feature requests, please use the issue tracker.

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Review our Code of Conduct and Contributor Guidelines.
  2. Fork the repo on GitHub
  3. Clone the project to your own machine
  4. Commit changes to your own branch
  5. Push your work back up to your fork
  6. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

🌎 Slack Community

Join our Open Source Community on Slack. It's FREE for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally sweet infrastructure.

πŸ“° Newsletter

Sign up for our newsletter and join 3,000+ DevOps engineers, CTOs, and founders who get insider access to the latest DevOps trends, so you can always stay in the know. Dropped straight into your Inbox every week β€” and usually a 5-minute read.

πŸ“† Office Hours

Join us every Wednesday via Zoom for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a live Q&A that you can’t find anywhere else. It's FREE for everyone!

License

License

Preamble to the Apache License, Version 2.0

Complete license is available in the LICENSE file.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Trademarks

All other trademarks referenced herein are the property of their respective owners.


Copyright Β© 2017-2024 Cloud Posse, LLC

README footer

Beacon

terraform-aws-ec2-bastion-server's People

Contributors

actions-user avatar aknysh avatar alexandrusavin avatar cloudpossebot avatar dylanbannon avatar goruha avatar gowiem avatar heathsnow avatar htplbc avatar joe-niland avatar karma0 avatar kevcube avatar korenyoni avatar max-lobur avatar maximmi avatar nitrocode avatar oavdeev-hs avatar osterman avatar renovate[bot] avatar sfc-gh-pkommini avatar sweetops avatar syphernl avatar tmeijn avatar vadim-hleif avatar yuekui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-aws-ec2-bastion-server's Issues

Using Bastion with EIP and replacing AMI's results in failure associating EIP

Describe the Bug

Whenever the AMI is updated, a new Bastion is created. This is fine, since a Bastion node is considered cattle and this ensures it remains (fairly) up-to-date.
Since v0.26.0 an EIP is assigned by default.

While this is fine, it causes issues in combination with replacing instances, since it tries to assign the EIP to the old instance rather than the new one.

The plan:

Terraform will perform the following actions:
  # module.bastion.aws_eip.default[0] will be updated in-place
  ~ resource "aws_eip" "default" {
        id                   = "eipalloc-xxxxxxxxxxxxx"
      ~ network_interface    = "eni-xxxxxxxxxxxxx" -> (known after apply)
        tags                 = {
            "Name"      = "project-staging-bastion"
            "Namespace" = "project"
            "Stage"     = "staging"
        }
        # (10 unchanged attributes hidden)
    }
  # module.bastion.aws_instance.default[0] must be replaced
-/+ resource "aws_instance" "default" {
      ~ ami                          = "ami-0d8f8483b8b8f0577" -> "ami-0daf8fddec6db520a" # forces replacement
      ~ arn                          = "arn:aws:ec2:eu-west-1:xxxxxxxxxxxxx:instance/i-xxxxxxxxxxxxx" -> (known after apply)
      ~ availability_zone            = "eu-west-1a" -> (known after apply)
      ~ cpu_core_count               = 1 -> (known after apply)
      ~ cpu_threads_per_core         = 2 -> (known after apply)
      - ebs_optimized                = false -> null
      - hibernation                  = false -> null
      + host_id                      = (known after apply)
      ~ id                           = "i-xxxxxxxxxxxxx" -> (known after apply)
      ~ instance_state               = "running" -> (known after apply)
      ~ ipv6_address_count           = 0 -> (known after apply)
      ~ ipv6_addresses               = [] -> (known after apply)
      + key_name                     = (known after apply)
      + outpost_arn                  = (known after apply)
      + password_data                = (known after apply)
      + placement_group              = (known after apply)
      ~ primary_network_interface_id = "eni-xxxxxxxxxxxxx" -> (known after apply)
      ~ private_dns                  = "ip-xxxxxxxxxxxxx.eu-west-1.compute.internal" -> (known after apply)
      ~ private_ip                   = "xxxxxxxxxxxxx" -> (known after apply)
      ~ public_dns                   = "ec2-xxxxxxxxxxxxx.eu-west-1.compute.amazonaws.com" -> (known after apply)
      ~ public_ip                    = "xxxxxxxxxxxxx" -> (known after apply)
      ~ secondary_private_ips        = [] -> (known after apply)
      ~ security_groups              = [] -> (known after apply)
        tags                         = {
            "Name"      = "project-staging-bastion"
            "Namespace" = "project"
            "Stage"     = "staging"
        }
      ~ tenancy                      = "default" -> (known after apply)
        # (10 unchanged attributes hidden)
      - credit_specification {
          - cpu_credits = "unlimited" -> null
        }
      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + snapshot_id           = (known after apply)
          + tags                  = (known after apply)
          + throughput            = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }
      ~ enclave_options {
          ~ enabled = false -> (known after apply)
        }
      + ephemeral_block_device {
          + device_name  = (known after apply)
          + no_device    = (known after apply)
          + virtual_name = (known after apply)
        }
      + network_interface {
          + delete_on_termination = (known after apply)
          + device_index          = (known after apply)
          + network_interface_id  = (known after apply)
        }
      ~ root_block_device {
          ~ device_name           = "/dev/xvda" -> (known after apply)
          ~ iops                  = 100 -> (known after apply)
          ~ kms_key_id            = "arn:aws:kms:eu-west-1:xxxxxxxxxxxxx:key/xxxxxxxxxxxxx" -> (known after apply)
          - tags                  = {} -> null
          ~ throughput            = 0 -> (known after apply)
          ~ volume_id             = "vol-xxxxxxxxxxxxx" -> (known after apply)
          ~ volume_type           = "gp2" -> (known after apply)
            # (3 unchanged attributes hidden)
        }
        # (1 unchanged block hidden)
    }

When being applied, this results in a failure:

Acquiring state lock. This may take a few moments...
module.bastion.aws_instance.default[0]: Destroying... [id=i-xxxxxxxxxxxxx]
module.bastion.aws_instance.default[0]: Still destroying... [id=i-xxxxxxxxxxxxx, 10s elapsed]
module.bastion.aws_instance.default[0]: Still destroying... [id=i-xxxxxxxxxxxxx, 20s elapsed]
module.bastion.aws_instance.default[0]: Still destroying... [id=i-xxxxxxxxxxxxx, 30s elapsed]
module.bastion.aws_instance.default[0]: Destruction complete after 32s
module.bastion.aws_instance.default[0]: Creating...
module.bastion.aws_instance.default[0]: Still creating... [10s elapsed]
module.bastion.aws_instance.default[0]: Still creating... [20s elapsed]
module.bastion.aws_instance.default[0]: Creation complete after 26s [id=i-xxxxxxxxxxxxx]
module.bastion.aws_eip.default[0]: Modifying... [id=eipalloc-xxxxxxxxxxxxx]
β•·
β”‚ Error: Failure associating EIP: InvalidInstanceID: The terminated instance 'i-xxxxxxxxxxxxx' is not in a valid state for this operation.
β”‚ 	status code: 400, request id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
β”‚ 
β”‚   with module.bastion.aws_eip.default[0],
β”‚   on .terraform/modules/bastion/main.tf line 97, in resource "aws_eip" "default":
β”‚   97: resource "aws_eip" "default" {
β”‚ 
β•΅

A second run afterwards results in the following plan:

Terraform will perform the following actions:
  # module.bastion.aws_eip.default[0] will be updated in-place
  ~ resource "aws_eip" "default" {
        id                   = "eipalloc-xxxxxxxxxxxxxxxxx"
      + network_interface    = "eni-xxxxxxxxxxxxxxxxx"
        tags                 = {
            "Name"      = "project-staging-bastion"
            "Namespace" = "project"
            "Stage"     = "staging"
        }
        # (7 unchanged attributes hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.

This apply succeeds just fine:

module.bastion.aws_eip.default[0]: Modifying... [id=eipalloc-xxxxxxxxxxxxxxxxx]
module.bastion.aws_eip.default[0]: Modifications complete after 2s [id=eipalloc-xxxxxxxxxxxxxxxxx]

Expected Behavior

The EIP to be assigned to the newly created instance

Steps to Reproduce

Steps to reproduce the behavior:

  1. Provision a Bastion instance with an EIP associated
  2. Change its AMI
  3. See that it will want to replace the instance
  4. See error

References

Default AMI does not exist

Describe the Bug

Default AMI does not exist.

Expected Behavior

Expected terraform apply to complete successfully.

Steps to Reproduce

Specified my infra as here:

module "ec2-bastion-server" {
  source  = "cloudposse/ec2-bastion-server/aws"
  version = "0.8.0"
  # insert the 6 required variables here
  name = "bastion"
  namespace = "poc"
  ssh_user = "root"
  stage = terraform.workspace
  subnets = data.aws_subnet_ids.example.ids
  vpc_id = data.aws_vpc.default.id
}

Screenshots

Error: InvalidAMIID.NotFound: The image id '[ami-efd0428f]' does not exist
	status code: 400, request id: 2082815b-f709-4270-aa75-04c432ff53a2

  on .terraform/modules/ec2-bastion-server/main.tf line 87, in resource "aws_instance" "default":
  87: resource "aws_instance" "default" {

Environment (please complete the following information):

OS: OSX

$ aws --version
aws-cli/2.0.52 Python/3.7.4 Darwin/19.6.0 exe/x86_64

Fix

I was able to fix problem by specifying different, existing AMI. I can make a PR with a fix if you'd like me to do so.

aws_iam_instance_profile tags attribute missing

Describe the Feature

All resources that support tags should get them.

Expected Behavior

When using the module tags map it should apply to all resources that support tags.

Use Case

I use terraform-compliance to ensure all resources that support tags get specific tags assigned.

Describe Ideal Solution

Add tags = module.this.tags to the aws_iam_instance_profile resource.

Update to use `terraform-aws-security-group` v2

Describe the Feature

The Terraform resources around Security Groups have evolved, and this module is using the outdated v0.3.3 of terraform-aws-security-group. It should be upgraded to use terraform-aws-security-group v2.

Additional Context

The upgrade may be a breaking upgrade and need migration notes. See:

Error: expected length of name to be in the range (1 - 64), got

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

module "bastion" {
  source                        = "cloudposse/ec2-bastion-server/aws"
  version                       = "0.17.0"

  ami                           = "ami-03130878b60947df3"
  instance_type                 = "t2.micro"
  id_length_limit               = 0

  vpc_id                        = aws_vpc.main.id
  associate_public_ip_address   = true
  subnets                       = aws_subnet.public.*.id
  allowed_cidr_blocks           = var.allowed_cidr_blocks

  ssh_user                      = "ec2-user"
  key_name                      = module.dispatch_key_pair.this_key_pair_key_name
  user_data                     = ["sudo amazon-linux-extras enable postgresql11"]

  tags = {
    name        = "${var.app_name}-bastion"
    environment = var.env
  }
}

This is the code.

Expected Behavior

We expect the bastion instance to be created successfully but instead the get the following error message:

Error: expected length of name to be in the range (1 - 64), got 

  on .terraform/modules/bastion/main.tf line 9, in resource "aws_iam_role" "default":
   9:   name  = module.this.id

Steps to Reproduce

Steps to reproduce the behavior:

  1. Use the code above
  2. With terraform 0.14.2
  3. Run terraform plan

Screenshots

Error: expected length of name to be in the range (1 - 64), got 

  on .terraform/modules/bastion/main.tf line 9, in resource "aws_iam_role" "default":
   9:   name  = module.this.id

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: macOS
  • Version: 10.15.7

Use an Autoscaling Group for Instance Replacement

I was using this module with the Route53 option and when modifying the instance class on an existing host I noticed that the Route53 record was not updated until I ran a second terraform apply.

I think an enhancement to this module would be to use an autoscaling group and an elastic ip address so that if the instance is replaced the domain doesn't have to be updated.

Override IAM policy attachment created

Describe the Feature

Ability to define the IAM policy attachment used.

Note: Assuming we move from inline to attachments.

Expected Behavior

When an IAM Policy attachment is specified, it is used in place of the one that would be created by default.

Use Case

We would like to control more closely the IAM policy to restrict access to different secrets. The default policy allows the host to effectively read any secret in the entire account, as I interpret it.

Describe Ideal Solution

New input: iam_policy_attachment -- takes some identifier of a resource for the policy attachment created by the user.
If set, this policy is used in place of the default created. If not, one is created by default.

Alternatives Considered

None.

Additional Context

The permissiveness of the default policy seems like a pretty big security risk for a bastion host module that users who may lack experience are going to utilize and may rollout unknowingly.

Make creation depend on a parameter

It would be nice to be able to disable bastion creation by setting a parameter on the module, e.g. "create = false":

module "ec2-bastion-server" {
  source  = "cloudposse/ec2-bastion-server/aws"
  version = "0.2.7"
  create  = false
  ...
}

Circular reference in eip/dns locals

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

There appears to be a circular reference in the locals according to tflint:

Failed to prepare rule checking; failed to eval an expression in .terraform/modules/bastion/main.tf:108; .terraform/modules/bastion/main.tf:7,25-42: circular reference found; local.public_dns -> local.eip_enabled -> local.public_dns_rendered -> local.eip_enabled:
Error: circular reference found
  on .terraform/modules/bastion/main.tf line 7, in locals:
   7:   public_dns_rendered = local.eip_enabled ? format("ec2-%s.%s.amazonaws.com",
local.public_dns -> local.eip_enabled -> local.public_dns_rendered -> local.eip_enabled

Expected Behavior

No circular dependency

Steps to Reproduce

Run tflint on a project which uses this module.

Screenshots

If applicable, add screenshots or logs to help explain your problem.

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: Linux
  • Version: 22.04

Additional Context

Add any other context about the problem here.

AMI will always upgrade

Describe the Bug

As of version 0.25.0, AMIs are dynamically sourced and will force redeployment of this EC2 instance resource whenever the AMI is found to be updated.

data "aws_ami" "default" {
  most_recent = "true"
...

Expected Behavior

Bastion host should be redeployed when I determine and not the AMI creator.

Additional Context

Perhaps use an optional ignore_changes?

  lifecycle {
    ignore_changes = [
      ami,
    ]
  }

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Base branch does not exist - skipping

Errored

These updates encountered an error and will be retried. Click on a checkbox below to force a retry now.

  • chore(deps): update terraform cloudposse/security-group/aws to v0.4.3 (main)

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

terraform
main.tf
  • cloudposse/route53-cluster-hostname/aws 0.12.2
  • cloudposse/security-group/aws 0.3.3
versions.tf
  • aws >= 2.55
  • hashicorp/terraform >= 0.13.0

  • Check this box to trigger a request for Renovate to run again on this repository

Add support for adding root EBS volume name

Describe the Feature

We are running cloud governance policies to check if appropriate tags are present in all resources. However, there is no way to add a name to the root EBS volume.

Expected Behavior

Need a parameter to add root EBS volume name.

Use Case

We are running cloud governance policies to check if appropriate tags are present in all resources.

Describe Ideal Solution

Add a parameter to add root EBS volume name.

Alternatives Considered

No response

Additional Context

No response

Unsupported Core Version 0.14.2

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

Initializing modules...

Error: Unsupported Terraform Core version

  on .terraform/modules/ec2-bastion-server.dns.this/versions.tf line 2, in terraform:
   2:   required_version = ">= 0.12.0, < 0.14.0"

Module module.ec2-bastion-server.module.dns.module.this (from
git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.2)
does not support Terraform version 0.14.2. To proceed, either choose another
supported Terraform version or update this version constraint. Version
constraints are normally set for good reason, so updating the constraint may
lead to other errors or unexpected behavior.

Expected Behavior

I expected the terraform init to setup the ec2-bastion-server module successfully.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Use terraform 0.14.2
  2. Use the cloudposse/ec2-bastion-server module
  3. Perform terraform init

Screenshots

Initializing modules...

Error: Unsupported Terraform Core version

  on .terraform/modules/ec2-bastion-server.dns.this/versions.tf line 2, in terraform:
   2:   required_version = ">= 0.12.0, < 0.14.0"

Module module.ec2-bastion-server.module.dns.module.this (from
git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.2)
does not support Terraform version 0.14.2. To proceed, either choose another
supported Terraform version or update this version constraint. Version
constraints are normally set for good reason, so updating the constraint may
lead to other errors or unexpected behavior.

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

  • OS: MacOS
  • Version 10.15.7

Additional Context

Add any other context about the problem here.

Add Example Usage

what

  • Add example invocation

why

  • We need this so we can soon enable automated continuous integration testing of module

Add support for multiple keypairs

It would be great if this module could make EC2s that multiple different users could ssh onto.

One way to do this would be to create an s3 bucket that IAM Users could upload public keys to, and then a cronjob could be setup in the user_data that would read in those keys.

Another way would be to have a var take in a list of public keys, and then the user_data could iterate over those keys and add them all as authorized keys.

I would be down to do either of these options if there is interest

Add support for additional IAM policies

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

We are running tasks on our bastion temporarily and need to add S3 permissions.

Expected Behavior

Either a list var additional_iam_policy_arns, or instance_profile_arn if the user wants to use a completely different role.

Use Case

We need some AWS permissions on our bastion

Describe Ideal Solution

see expected behavior

Alternatives Considered

there's probably a better way than performing aws api calls from the bastion, but there may be other use cases where additional IAM policies are useful to others.

Additional Context

Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.