Skip to content

Commit 06c5c9e

Browse files
committed
Generate random password
1 parent 0fc68ca commit 06c5c9e

File tree

4 files changed

+48
-24
lines changed

4 files changed

+48
-24
lines changed

workshop/aws/ec2/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ The following variables are available. Edit `terraform.tfvars` to reflect what y
4242
- `aws_region`: Which region do you want the instances in?
4343
- `aws_instance_count`: How many instances?
4444
- `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
4645

4746
### Optional variables
4847

@@ -68,6 +67,22 @@ terraform apply \
6867
-input=false
6968
```
7069

70+
Once the apply is complete, the output will contain the public IP addresses, instance names and the _(automatically generated)_ instance password.
71+
72+
### Example output from Terraform
73+
74+
``` text
75+
Apply complete! Resources: 10 added, 0 changed, 0 destroyed.
76+
77+
Outputs:
78+
79+
login_details = tolist([
80+
"workshop-01, 10.1.1.1, mKV50oR36MgASJd3",
81+
"workshop-02, 10.1.1.2, mKV50oR36MgASJd3",
82+
"workshop-03, 10.1.1.3, mKV50oR36MgASJd3",
83+
])
84+
```
85+
7186
<!--
7287
Or you use the provided script `up` to request instances:
7388

workshop/aws/ec2/main.tf

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,19 @@ resource "aws_route" "o11y-ws-route" {
173173
# route_table_id = aws_route_table.o11y-ws-rt.id
174174
# }
175175

176+
resource "random_string" "password" {
177+
length = 16
178+
override_special = "_%@$#!"
179+
}
180+
176181
locals {
177182
template_vars = {
178183
access_token = var.splunk_access_token
179184
rum_token = var.splunk_rum_token
180185
realm = var.splunk_realm
181186
presetup = var.splunk_presetup
182187
jdk = var.splunk_jdk
183-
instance_password = var.instance_password
188+
instance_password = random_string.password.result
184189
}
185190
}
186191

@@ -219,12 +224,21 @@ resource "aws_instance" "observability-instance" {
219224
}
220225
}
221226

222-
output "instance_details" {
227+
#output "instance_details" {
228+
# value = formatlist(
229+
# "%s, %s, %s, %s",
230+
# aws_instance.observability-instance[*].tags["Instance"],
231+
# aws_instance.observability-instance.*.private_ip,
232+
# aws_instance.observability-instance.*.public_ip,
233+
# aws_instance.observability-instance[*].tags["Subnet"]
234+
# )
235+
#}
236+
237+
output "login_details" {
223238
value = formatlist(
224-
"%s, %s, %s, %s",
239+
"%s, %s, %s",
225240
aws_instance.observability-instance[*].tags["Instance"],
226-
aws_instance.observability-instance.*.private_ip,
227241
aws_instance.observability-instance.*.public_ip,
228-
aws_instance.observability-instance[*].tags["Subnet"]
242+
local.template_vars.instance_password
229243
)
230-
}
244+
}

workshop/aws/ec2/outputs.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
output "ip_addresses" {
2-
value = aws_instance.observability-instance.*.public_ip
3-
}
1+
#output "ip_addresses" {
2+
# value = aws_instance.observability-instance.*.public_ip
3+
#}
44

5-
output "instance_names" {
6-
value = aws_instance.observability-instance[*].tags["Instance"]
7-
}
5+
#output "instance_names" {
6+
# value = aws_instance.observability-instance[*].tags["Instance"]
7+
#}
88

9-
output "public_subnet_ids" {
10-
value = aws_subnet.o11y_ws_subnets.*.id
11-
}
9+
#output "public_subnet_ids" {
10+
# value = aws_subnet.o11y_ws_subnets.*.id
11+
#}
1212

13-
output "instance_password" {
14-
value = var.instance_password
15-
}
13+
#output "instance_password" {
14+
# value = random_string.password.result
15+
#}

workshop/aws/ec2/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ variable "slug" {
4040
description = "Short name/tag, e.g. acme. Used to derive project and hostnames, AWS tags and terraform workspace"
4141
}
4242

43-
variable "instance_password" {
44-
description = "Password for the EC2 instance"
45-
nullable = false
46-
}
47-
4843
variable "splunk_access_token" {
4944
description = "Splunk Oberservability Cloud Access Token"
5045
default = ""

0 commit comments

Comments
 (0)