Skip to content

Commit 78779d3

Browse files
committed
Fixed issue #154, instance password
1 parent 7bc8c08 commit 78779d3

File tree

6 files changed

+52
-32
lines changed

6 files changed

+52
-32
lines changed

workshop/aws/ec2/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,24 @@ The file `terraform.tfvars` is ignored by git and should not be committed to the
3737

3838
The following variables are available. Edit `terraform.tfvars` to reflect what you need.
3939

40+
### Required variables
41+
4042
- `aws_region`: Which region do you want the instances in?
4143
- `aws_instance_count`: How many instances?
42-
- `slug`: Workshop name slug that will be used to tag aws resources (keep this short as this forms part of the instance hostname e.g. `acme`)
44+
- `slug`: Short name/tag, e.g. acme. Used to derive project and hostnames, AWS tags and terraform workspace e.g. `emea-ws`)
45+
- `instance_password`: Password for the EC2 instance
46+
47+
### Optional variables
48+
4349
- `splunk_access_token`: Observability Access Token
4450
- `splunk_rum_token`: Observability RUM Token
4551
- `splunk_realm`: Observability Realm
46-
- `splunk_presetup`: Provide a preconfigured instance (OTel Collector and Online Boutique deployed with RUM enabled)
47-
- `splunk_jdk`: Install OpenJDK and Maven on the instance
52+
- `subnet_count`: How many subnets to create. The default is 2.
53+
54+
### Instance type variables
55+
56+
- `splunk_presetup`: Provide a preconfigured instance (OTel Collector and Online Boutique deployed with RUM enabled). The default is FALSE.
57+
- `splunk_jdk`: Install OpenJDK and Maven on the instance. The default is FALSE.
4858

4959
## 6. Create a Terraform plan
5060

@@ -58,6 +68,7 @@ terraform apply \
5868
-input=false
5969
```
6070

71+
<!--
6172
Or you use the provided script `up` to request instances:
6273
6374
Install the prerequisites, e.g. on Mac: `brew install terraform jq pssh`
@@ -69,3 +80,4 @@ Then use the script:
6980
```
7081
7182
This will create a terraform workspace `o11y-for-myproject`, request 12 instances and ensure all instances have completed provisioning.
83+
-->

workshop/aws/ec2/main.tf

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ resource "aws_subnet" "o11y_ws_subnets" {
5656
# }
5757

5858
resource "aws_security_group" "o11y-ws-sg" {
59-
name = "Observability-Workshop-SG"
59+
name = "Observability-Workshop-SG"
6060
vpc_id = aws_vpc.o11y-ws-vpc.id
61-
61+
6262
ingress {
6363
from_port = 22
6464
to_port = 22
@@ -175,20 +175,20 @@ resource "aws_route" "o11y-ws-route" {
175175

176176
locals {
177177
template_vars = {
178-
access_token = var.splunk_access_token
179-
rum_token = var.splunk_rum_token
180-
realm = var.splunk_realm
181-
presetup = var.splunk_presetup
182-
jdk = var.splunk_jdk
178+
access_token = var.splunk_access_token
179+
rum_token = var.splunk_rum_token
180+
realm = var.splunk_realm
181+
presetup = var.splunk_presetup
182+
jdk = var.splunk_jdk
183+
instance_password = var.instance_password
183184
}
184185
}
185186

186187
resource "aws_instance" "observability-instance" {
187188
count = var.aws_instance_count
188189
ami = data.aws_ami.latest-ubuntu.id
189190
instance_type = var.aws_instance_type
190-
# subnet_id = aws_subnet.o11y-ws-subnet.id
191-
subnet_id = "${aws_subnet.o11y_ws_subnets.*.id[ count.index % length(aws_subnet.o11y_ws_subnets) ]}"
191+
subnet_id = aws_subnet.o11y_ws_subnets.*.id[count.index % length(aws_subnet.o11y_ws_subnets)]
192192
vpc_security_group_ids = [aws_security_group.o11y-ws-sg.id]
193193

194194
user_data = templatefile("${path.module}/templates/userdata.yaml", merge(local.template_vars,
@@ -206,7 +206,7 @@ resource "aws_instance" "observability-instance" {
206206
#Name = "observability-${count.index + 1}"
207207
Instance = "${lower(var.slug)}-${format("%02d", count.index + 1)}"
208208
Name = "${lower(var.slug)}-${format("%02d", count.index + 1)}"
209-
Subnet = "${aws_subnet.o11y_ws_subnets.*.id[ count.index % length(aws_subnet.o11y_ws_subnets) ]}"
209+
Subnet = "${aws_subnet.o11y_ws_subnets.*.id[count.index % length(aws_subnet.o11y_ws_subnets)]}"
210210
}
211211
)
212212

@@ -219,14 +219,12 @@ resource "aws_instance" "observability-instance" {
219219
}
220220
}
221221

222-
223-
224222
output "instance_details" {
225-
value = formatlist(
226-
"%s, %s, %s, %s",
223+
value = formatlist(
224+
"%s, %s, %s, %s",
227225
aws_instance.observability-instance[*].tags["Instance"],
228226
aws_instance.observability-instance.*.private_ip,
229227
aws_instance.observability-instance.*.public_ip,
230228
aws_instance.observability-instance[*].tags["Subnet"]
231229
)
232-
}
230+
}

workshop/aws/ec2/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ output "instance_names" {
99
output "public_subnet_ids" {
1010
value = aws_subnet.o11y_ws_subnets.*.id
1111
}
12+
13+
output "instance_password" {
14+
value = var.instance_password
15+
}

workshop/aws/ec2/templates/userdata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#cloud-config
22
ssh_pwauth: yes
3-
password: Observability2023!
3+
password: ${instance_password}
44
chpasswd:
55
expire: false
66

workshop/aws/ec2/terraform.tfvars.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
aws_region = ""
33
aws_instance_count = ""
44
slug = ""
5+
instance_password = ""
56

67
# required if pre-setup is desired, optional otherwise. See variables.tf and README.md
78
splunk_access_token = ""

workshop/aws/ec2/variables.tf

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
variable "cloud_init_print" {
22
description = "Show rendered cloud_init output"
3-
type = bool
4-
default = false
3+
type = bool
4+
default = false
55
}
66

77
variable "splunk_presetup" {
88
description = "Presetup the instance? (true/false)"
9-
type = bool
10-
default = false
9+
type = bool
10+
default = false
1111
}
1212

1313
variable "splunk_jdk" {
1414
description = "Enabled Java Development environment? (true/false)"
15-
type = bool
16-
default = false
15+
type = bool
16+
default = false
1717
}
1818

1919
variable "aws_instance_count" {
2020
description = "Instance Count (Usually 1)"
21-
nullable = false
21+
nullable = false
2222
}
2323

2424
variable "subnet_count" {
25-
description = "Subnet Count (Usually 1 for small workshops, but can be 2 or 3 for larger one, but never 4 and be aware some regions only support 2 due to limited flavor availabiity)"
26-
nullable = false
27-
default = "2"
25+
description = "Subnet Count (Usually 1 for small workshops, but can be 2 or 3 for larger one, but never 4 and be aware some regions only support 2 due to limited flavour availabiity)"
26+
nullable = false
27+
default = "2"
2828
}
2929

3030
variable "public_subnet_ids" {
@@ -33,11 +33,16 @@ variable "public_subnet_ids" {
3333

3434
variable "aws_region" {
3535
description = "AWS Region (for example: us-west-2)"
36-
nullable = false
36+
nullable = false
3737
}
3838

3939
variable "slug" {
40-
description = "Short name/tag, e.g. acme. Used to derive project and host names, aws tags and terraform workspace."
40+
description = "Short name/tag, e.g. acme. Used to derive project and hostnames, AWS tags and terraform workspace"
41+
}
42+
43+
variable "instance_password" {
44+
description = "Password for the EC2 instance"
45+
nullable = false
4146
}
4247

4348
variable "splunk_access_token" {
@@ -62,7 +67,7 @@ data "aws_ami" "latest-ubuntu" {
6267

6368
filter {
6469
name = "name"
65-
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
70+
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
6671
}
6772

6873
filter {

0 commit comments

Comments
 (0)