Skip to content

Commit a6b846c

Browse files
committed
Sync AWS and Multipass terraform/cloud-init
1 parent aa0d06a commit a6b846c

File tree

3 files changed

+48
-63
lines changed

3 files changed

+48
-63
lines changed

multipass/main.tf

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,71 +11,74 @@ terraform {
1111

1212
variable "splunk_access_token" {
1313
description = "Splunk Observability Cloud Access Token"
14-
type = string
15-
default = ""
14+
type = string
15+
default = ""
1616
}
1717

1818
variable "splunk_rum_token" {
1919
description = "Splunk Observability Cloud RUM Token"
20-
type = string
21-
default = ""
20+
type = string
21+
default = ""
2222
}
2323

2424
variable "splunk_realm" {
2525
description = "Splunk Observability Cloud Realm (us0, us1, us2, eu0, jp0, au0)"
26-
type = string
27-
default = ""
26+
type = string
27+
default = ""
2828
}
2929

3030
variable "splunk_presetup" {
3131
description = "Pre configure the instance? (true/false)"
32-
type = bool
33-
default = false
32+
type = bool
33+
default = false
3434
}
3535

3636
variable "splunk_jdk" {
3737
description = "Enabled Java Development environment? (true/false)"
38-
type = bool
39-
default = false
38+
type = bool
39+
default = false
4040
}
4141

42-
data "template_file" "user_data" {
43-
template = "${file("../workshop/aws/ec2/templates/userdata.yaml")}"
44-
vars = {
45-
access_token = "${var.splunk_access_token}"
46-
rum_token = "${var.splunk_rum_token}"
47-
realm = "${var.splunk_realm}"
48-
presetup = "${var.splunk_presetup}"
49-
jdk = "${var.splunk_jdk}"
42+
resource "random_string" "hostname" {
43+
length = 4
44+
lower = true
45+
upper = false
46+
special = false
47+
numeric = false
48+
}
49+
50+
locals {
51+
template_vars = {
52+
access_token = var.splunk_access_token
53+
rum_token = var.splunk_rum_token
54+
realm = var.splunk_realm
55+
presetup = var.splunk_presetup
56+
jdk = var.splunk_jdk
5057
instance_name = "${random_string.hostname.result}"
5158
}
5259
}
5360

61+
data "template_file" "user_data" {
62+
template = templatefile("../workshop/aws/ec2/templates/userdata.yaml", merge(local.template_vars))
63+
}
64+
5465
resource "local_file" "user_data" {
5566
filename = "ubuntu-cloudinit.yml"
5667
content = data.template_file.user_data.rendered
5768
}
5869

59-
resource "random_string" "hostname" {
60-
length = 4
61-
lower = true
62-
upper = false
63-
special = false
64-
numeric = false
65-
}
66-
6770
resource "multipass_instance" "ubuntu" {
68-
name = random_string.hostname.result
69-
memory = "8GiB"
70-
disk = "32GiB"
71-
cpus = 4
72-
image = "jammy"
71+
name = random_string.hostname.result
72+
memory = "8GiB"
73+
disk = "32GiB"
74+
cpus = 4
75+
image = "jammy"
7376
cloudinit_file = local_file.user_data.filename
7477

7578
lifecycle {
7679
precondition {
7780
# if splunk_presetup=true, tokens and realm cannot be empty
78-
condition = var.splunk_presetup ? try(var.splunk_access_token, "") != "" && try(var.splunk_realm, "") != "" && try(var.splunk_rum_token, "") != "": true
81+
condition = var.splunk_presetup ? try(var.splunk_access_token, "") != "" && try(var.splunk_realm, "") != "" && try(var.splunk_rum_token, "") != "" : true
7982
error_message = "When requesting a pre-setup instance, splunk_realm, splunk_access_token and splunk_rum_token are required and cannot be null/empty"
8083
}
8184
}

workshop/aws/ec2/config.tf

Lines changed: 0 additions & 18 deletions
This file was deleted.

workshop/aws/ec2/main.tf

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
provider "aws" {
2-
# profile = "default"
3-
region = var.aws_region
2+
# profile = "default"
3+
region = var.aws_region
44
}
55

66
locals {
77
common_tags = {
8-
Component = "o11y-for-${var.slug}"
8+
Component = "o11y-for-${var.slug}"
99
Environment = "production"
1010
}
1111
}
1212

1313
resource "aws_vpc" "o11y-ws-vpc" {
14-
cidr_block = "10.13.0.0/16"
14+
cidr_block = "10.13.0.0/16"
1515
enable_dns_support = true
1616
enable_dns_hostnames = true
1717
tags = merge(
@@ -36,8 +36,8 @@ resource "aws_subnet" "o11y-ws-subnet" {
3636
}
3737

3838
resource "aws_security_group" "o11y-ws-sg" {
39-
name = "Observability-Workshop-SG"
40-
vpc_id = aws_vpc.o11y-ws-vpc.id
39+
name = "Observability-Workshop-SG"
40+
vpc_id = aws_vpc.o11y-ws-vpc.id
4141

4242
ingress {
4343
from_port = 22
@@ -143,10 +143,10 @@ resource "aws_route_table_association" "o11y-ws-rta" {
143143
locals {
144144
template_vars = {
145145
access_token = var.splunk_access_token
146-
rum_token = var.splunk_rum_token
147-
realm = var.splunk_realm
148-
presetup = var.splunk_presetup
149-
jdk = var.splunk_jdk
146+
rum_token = var.splunk_rum_token
147+
realm = var.splunk_realm
148+
presetup = var.splunk_presetup
149+
jdk = var.splunk_jdk
150150
}
151151
}
152152

@@ -156,10 +156,10 @@ resource "aws_instance" "observability-instance" {
156156
instance_type = var.aws_instance_type
157157
subnet_id = aws_subnet.o11y-ws-subnet.id
158158
vpc_security_group_ids = [aws_security_group.o11y-ws-sg.id]
159-
user_data = templatefile("${path.module}/templates/userdata.yaml", merge(local.template_vars,
159+
user_data = templatefile("${path.module}/templates/userdata.yaml", merge(local.template_vars,
160160
{
161161
instance_name = "${var.slug}-${count.index + 1}"
162-
}))
162+
}))
163163

164164
root_block_device {
165165
volume_size = var.instance_disk_aws
@@ -177,7 +177,7 @@ resource "aws_instance" "observability-instance" {
177177
lifecycle {
178178
precondition {
179179
# if splunk_presetup=true, tokens and realm cannot be empty
180-
condition = var.splunk_presetup ? try(var.splunk_access_token, "") != "" && try(var.splunk_realm, "") != "" && try(var.splunk_rum_token, "") != "": true
180+
condition = var.splunk_presetup ? try(var.splunk_access_token, "") != "" && try(var.splunk_realm, "") != "" && try(var.splunk_rum_token, "") != "" : true
181181
error_message = "When requesting a pre-setup instance, splunk_realm, splunk_access_token and splunk_rum_token are required and cannot be null/empty"
182182
}
183183
}

0 commit comments

Comments
 (0)