Skip to content

Commit d6a3c89

Browse files
authored
Update default AMI ID (#40)
1 parent 1ab9dce commit d6a3c89

File tree

8 files changed

+295
-4
lines changed

8 files changed

+295
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Available targets:
9999
| Name | Description | Type | Default | Required |
100100
|------|-------------|------|---------|:--------:|
101101
| allowed\_cidr\_blocks | A list of CIDR blocks allowed to connect | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
102-
| ami | AMI to use | `string` | `"ami-efd0428f"` | no |
102+
| ami | AMI to use | `string` | `"ami-084ef34fdfdd7384c"` | no |
103103
| associate\_public\_ip\_address | Whether to associate a public IP to the instance. | `bool` | `true` | no |
104104
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
105105
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | `string` | `"-"` | no |

docs/terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| Name | Description | Type | Default | Required |
2121
|------|-------------|------|---------|:--------:|
2222
| allowed\_cidr\_blocks | A list of CIDR blocks allowed to connect | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
23-
| ami | AMI to use | `string` | `"ami-efd0428f"` | no |
23+
| ami | AMI to use | `string` | `"ami-084ef34fdfdd7384c"` | no |
2424
| associate\_public\_ip\_address | Whether to associate a public IP to the instance. | `bool` | `true` | no |
2525
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
2626
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | `string` | `"-"` | no |

examples/complete/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ variable "instance_type" {
6060

6161
variable "ami" {
6262
type = string
63-
default = "ami-efd0428f"
63+
default = "ami-084ef34fdfdd7384c"
6464
description = "AMI to use"
6565
}
6666

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
region = "us-east-2"
2+
3+
availability_zones = ["us-east-2a", "us-east-2b"]
4+
5+
namespace = "eg"
6+
7+
stage = "test"
8+
9+
name = "ec2-bastion"
10+
11+
instance_type = "t3a.nano"
12+
13+
ssh_user = "ubuntu"
14+
15+
ssh_key_path = "./secrets"
16+
17+
generate_ssh_key = true
18+
19+
user_data = [
20+
"apt-get install -y postgresql-client-common"
21+
]
22+
23+
security_groups = []
24+
25+
ingress_security_groups = []
26+
27+
root_block_device_encrypted = true
28+
29+
metadata_http_tokens_required = true
30+
31+
associate_public_ip_address = true

examples/latest-ami/main.tf

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
module "vpc" {
6+
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.16.1"
7+
namespace = var.namespace
8+
stage = var.stage
9+
name = var.name
10+
cidr_block = "172.16.0.0/16"
11+
}
12+
13+
module "subnets" {
14+
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.26.0"
15+
availability_zones = var.availability_zones
16+
namespace = var.namespace
17+
stage = var.stage
18+
name = var.name
19+
vpc_id = module.vpc.vpc_id
20+
igw_id = module.vpc.igw_id
21+
cidr_block = module.vpc.vpc_cidr_block
22+
nat_gateway_enabled = false
23+
nat_instance_enabled = false
24+
}
25+
26+
module "aws_key_pair" {
27+
source = "git::https://github.com/cloudposse/terraform-aws-key-pair.git?ref=tags/0.13.1"
28+
namespace = var.namespace
29+
stage = var.stage
30+
name = var.name
31+
attributes = ["ssh", "key"]
32+
ssh_public_key_path = var.ssh_key_path
33+
generate_ssh_key = var.generate_ssh_key
34+
}
35+
36+
# Retrieves the most recent Ubuntu 20.04 AMI
37+
data "aws_ami" "ubuntu" {
38+
most_recent = true
39+
40+
filter {
41+
name = "name"
42+
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
43+
}
44+
45+
filter {
46+
name = "virtualization-type"
47+
values = ["hvm"]
48+
}
49+
50+
owners = ["099720109477"] # Canonical
51+
}
52+
53+
module "ec2_bastion" {
54+
source = "../../"
55+
56+
enabled = var.enabled
57+
58+
ami = data.aws_ami.ubuntu.id
59+
instance_type = var.instance_type
60+
61+
name = var.name
62+
namespace = var.namespace
63+
stage = var.stage
64+
tags = var.tags
65+
attributes = var.attributes
66+
67+
security_groups = compact(concat([module.vpc.vpc_default_security_group_id], var.security_groups))
68+
ingress_security_groups = var.ingress_security_groups
69+
subnets = module.subnets.public_subnet_ids
70+
ssh_user = var.ssh_user
71+
key_name = module.aws_key_pair.key_name
72+
73+
user_data = var.user_data
74+
75+
vpc_id = module.vpc.vpc_id
76+
}

examples/latest-ami/outputs.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
output "instance_id" {
2+
value = module.ec2_bastion.instance_id
3+
description = "Instance ID"
4+
}
5+
6+
output "ssh_user" {
7+
value = var.ssh_user
8+
description = "SSH user"
9+
}
10+
11+
output "security_group_id" {
12+
value = module.ec2_bastion.security_group_id
13+
description = "Security group ID"
14+
}
15+
16+
output "role" {
17+
value = module.ec2_bastion.role
18+
description = "Name of AWS IAM Role associated with the instance"
19+
}
20+
21+
output "public_ip" {
22+
value = module.ec2_bastion.public_ip
23+
description = "Public IP of the instance (or EIP)"
24+
}
25+
26+
output "private_ip" {
27+
value = module.ec2_bastion.private_ip
28+
description = "Private IP of the instance"
29+
}
30+
31+
output "public_subnet_cidrs" {
32+
value = module.subnets.public_subnet_cidrs
33+
}
34+
35+
output "private_subnet_cidrs" {
36+
value = module.subnets.private_subnet_cidrs
37+
}
38+
39+
output "vpc_cidr" {
40+
value = module.vpc.vpc_cidr_block
41+
}
42+
43+
output "key_name" {
44+
value = module.aws_key_pair.key_name
45+
}
46+
47+
output "public_key" {
48+
value = module.aws_key_pair.public_key
49+
}

examples/latest-ami/variables.tf

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
variable "enabled" {
2+
type = bool
3+
default = true
4+
}
5+
6+
variable "namespace" {
7+
description = "Namespace (e.g. `eg` or `cp`)"
8+
type = string
9+
}
10+
11+
variable "stage" {
12+
description = "Stage (e.g. `prod`, `dev`, `staging`)"
13+
type = string
14+
}
15+
16+
variable "name" {
17+
description = "Name (e.g. `app` or `bastion`)"
18+
type = string
19+
}
20+
21+
variable "delimiter" {
22+
type = string
23+
default = "-"
24+
description = "Delimiter to be used between `namespace`, `stage`, `name` and `attributes`"
25+
}
26+
27+
variable "attributes" {
28+
type = list(string)
29+
default = []
30+
description = "Additional attributes (e.g. `1`)"
31+
}
32+
33+
variable "tags" {
34+
type = map(string)
35+
default = {}
36+
description = "Additional tags (e.g. map('BusinessUnit`,`XYZ`)"
37+
}
38+
39+
variable "region" {
40+
type = string
41+
description = "AWS region"
42+
}
43+
44+
variable "availability_zones" {
45+
type = list(string)
46+
description = "List of Availability Zones where subnets will be created"
47+
}
48+
49+
variable "zone_id" {
50+
type = string
51+
default = ""
52+
description = "Route53 DNS Zone ID"
53+
}
54+
55+
variable "instance_type" {
56+
type = string
57+
default = "t2.micro"
58+
description = "Elastic cache instance type"
59+
}
60+
61+
variable "user_data" {
62+
type = list(string)
63+
default = []
64+
description = "User data content"
65+
}
66+
67+
variable "ssh_user" {
68+
type = string
69+
description = "Default SSH user for this AMI. e.g. `ec2user` for Amazon Linux and `ubuntu` for Ubuntu systems"
70+
}
71+
72+
variable "ssh_key_path" {
73+
type = string
74+
description = "Save location for ssh public keys generated by the module"
75+
}
76+
77+
variable "generate_ssh_key" {
78+
type = bool
79+
description = "Whether or not to generate an SSH key"
80+
}
81+
82+
variable "security_groups" {
83+
type = list(string)
84+
description = "AWS security group IDs"
85+
}
86+
87+
variable "ingress_security_groups" {
88+
type = list(string)
89+
description = "AWS security group IDs allowed ingress to instance"
90+
}
91+
92+
variable "allowed_cidr_blocks" {
93+
type = list(string)
94+
description = "A list of CIDR blocks allowed to connect"
95+
96+
default = [
97+
"0.0.0.0/0",
98+
]
99+
}
100+
101+
variable "root_block_device_encrypted" {
102+
type = bool
103+
default = false
104+
description = "Whether to encrypt the root block device"
105+
}
106+
107+
variable "root_block_device_volume_size" {
108+
type = number
109+
default = 8
110+
description = "The volume size (in GiB) to provision for the root block device. It cannot be smaller than the AMI it refers to."
111+
}
112+
113+
variable "metadata_http_endpoint_enabled" {
114+
type = bool
115+
default = true
116+
description = "Whether the metadata service is available"
117+
}
118+
119+
variable "metadata_http_put_response_hop_limit" {
120+
type = number
121+
default = 1
122+
description = "The desired HTTP PUT response hop limit (between 1 and 64) for instance metadata requests."
123+
}
124+
125+
variable "metadata_http_tokens_required" {
126+
type = bool
127+
default = false
128+
description = "Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2."
129+
}
130+
131+
variable "associate_public_ip_address" {
132+
type = bool
133+
default = true
134+
description = "Whether to associate public IP to the instance."
135+
}

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ variable "instance_type" {
5151

5252
variable "ami" {
5353
type = string
54-
default = "ami-efd0428f"
54+
default = "ami-084ef34fdfdd7384c"
5555
description = "AMI to use"
5656
}
5757

0 commit comments

Comments
 (0)