Skip to content

Commit 1c8fcda

Browse files
committed
Changed to use SWiPE ID
1 parent 609e742 commit 1c8fcda

File tree

4 files changed

+64
-68
lines changed

4 files changed

+64
-68
lines changed

content/en/resources/local-hosting/multipass.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ description: Learn how to create a local hosting environment with Multipass - Wi
77
Install [Multipass](https://multipass.run/) and Terraform for your operating system. On a Mac (Intel), you can also install via [Homebrew](https://brew.sh/) e.g.
88

99
```text
10-
brew install multipass
11-
brew install terraform
10+
brew install multipass terraform jq
1211
```
1312

1413
Clone workshop repository:
@@ -17,7 +16,7 @@ Clone workshop repository:
1716
git clone https://github.com/splunk/observability-workshop
1817
```
1918

20-
Change into multipass directory:
19+
Change into Multipass directory:
2120

2221
```bash
2322
cd observability-workshop/local-hosting/multipass
@@ -33,7 +32,7 @@ Additional requirements for running your own **Log Observer Connect** connection
3332
- Create an index called **splunk4rookies-workshop**
3433
- Make sure the Service account user used in the **Log observer Connect** connection has access to the **splunk4rookies-workshop** index (you can remove all other indexes, as all workshop log data should go to this index).
3534

36-
Initialise Terraform:
35+
Initialize Terraform:
3736

3837
{{< tabs >}}
3938
{{% tab title="Command" %}}
@@ -71,12 +70,7 @@ cp terraform.tfvars.template terraform.tfvars
7170

7271
The following Terraform variables are required:
7372

74-
- `splunk_access_token`: Observability Cloud Access Token
75-
- `splunk_api_token`: Observability Cloud API Token
76-
- `splunk_rum_token`: Observability Cloud RUM Token
77-
- `splunk_realm`: Observability Cloud Realm e.g. `eu0`
78-
- `splunk_hec_url`: Splunk HEC URL. Do not use a `raw` endpoint, use the `event` endpoint so logs process correctly.
79-
- `splunk_hec_token`: Splunk HEC Token
73+
- `swipe_id`: [SWiPE ID](https://swipe.splunk.com/) for the instance
8074
- `splunk_index`: Splunk Index to send logs to. Defaults to `splunk4rookies-workshop`.
8175

8276
Instance type variables:

local-hosting/multipass/main.tf

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,19 @@ terraform {
66
source = "larstobi/multipass"
77
version = "~> 1.4.1"
88
}
9+
http = {
10+
source = "hashicorp/http"
11+
version = "~> 3.4.0"
12+
}
913
}
1014
}
1115

12-
variable "splunk_access_token" {
13-
description = "Splunk Observability Cloud Access Token"
14-
type = string
15-
nullable = false
16-
}
17-
18-
variable "splunk_api_token" {
19-
description = "Splunk Observability Cloud API Token"
20-
type = string
21-
nullable = false
22-
}
23-
24-
variable "splunk_rum_token" {
25-
description = "Splunk Observability Cloud RUM Token"
26-
type = string
27-
nullable = false
28-
}
29-
30-
variable "splunk_realm" {
31-
description = "Splunk Observability Cloud Realm (us0, us1, us2, eu0, jp0, au0)"
16+
variable "swipe_id" {
17+
description = "Splunk Swipe ID"
3218
type = string
3319
default = ""
3420
}
3521

36-
variable "splunk_hec_token" {
37-
description = "Splunk Cloud HEC Token"
38-
type = string
39-
nullable = false
40-
}
41-
42-
variable "splunk_hec_url" {
43-
description = "Splunk Cloud HEC URL"
44-
type = string
45-
nullable = false
46-
}
47-
4822
variable "splunk_index" {
4923
description = "Splunk Cloud Index"
5024
type = string
@@ -111,14 +85,34 @@ resource "random_string" "hostname" {
11185
numeric = false
11286
}
11387

88+
# Fetch tokens from Splunk Swipe API
89+
data "http" "swipe_tokens" {
90+
url = "https://swipe.splunk.show/api?id=${var.swipe_id}"
91+
92+
request_headers = {
93+
"Content-Type" = "application/json"
94+
}
95+
}
96+
11497
locals {
98+
# Process API response
99+
swipe_data = try(jsondecode(data.http.swipe_tokens.response_body), {})
100+
101+
# Extract values from API response
102+
access_token = try(local.swipe_data.INGEST, "")
103+
api_token = try(local.swipe_data.API, "")
104+
rum_token = try(local.swipe_data.RUM, "")
105+
realm = try(local.swipe_data.REALM, "")
106+
hec_token = try(local.swipe_data.HEC_TOKEN, "")
107+
hec_url = try(local.swipe_data.HEC_URL, "")
108+
115109
template_vars = {
116-
access_token = var.splunk_access_token
117-
rum_token = var.splunk_rum_token
118-
api_token = var.splunk_api_token
119-
realm = var.splunk_realm
120-
hec_token = var.splunk_hec_token
121-
hec_url = var.splunk_hec_url
110+
access_token = local.access_token
111+
rum_token = local.rum_token
112+
api_token = local.api_token
113+
realm = local.realm
114+
hec_token = local.hec_token
115+
hec_url = local.hec_url
122116
index = var.splunk_index
123117
presetup = var.splunk_presetup
124118
otel_demo = var.otel_demo
@@ -132,6 +126,7 @@ locals {
132126
}
133127
}
134128

129+
135130
resource "local_file" "user_data" {
136131
filename = "ubuntu-cloudinit.yml"
137132
content = templatefile("templates/${var.user_data_tpl}", merge(local.template_vars))
@@ -154,14 +149,18 @@ resource "multipass_instance" "ubuntu" {
154149

155150
lifecycle {
156151
precondition {
157-
# if splunk_presetup=true, tokens and realm cannot be empty
158-
condition = var.splunk_presetup ? try(var.splunk_access_token, "") != "" && try(var.splunk_realm, "") != "" && try(var.splunk_rum_token, "") != "" : true
159-
error_message = "When requesting a pre-setup instance, splunk_realm, splunk_access_token and splunk_rum_token are required and cannot be null/empty"
160-
}
161-
precondition {
162-
# if access_token and realm cannot be empty.
163-
condition = var.splunk_access_token != "" && var.splunk_realm != ""
164-
error_message = "splunk_realm and splunk_access_token are required and cannot be null/empty."
152+
condition = try(local.swipe_data.message, "") != "Workshop ID not found"
153+
error_message = "SWiPE ID not found. Please check the ID and try again."
165154
}
155+
# precondition {
156+
# # if splunk_presetup=true, tokens and realm cannot be empty
157+
# condition = var.splunk_presetup ? try(local.access_token, "") != "" && try(local.realm, "") != "" && try(local.rum_token, "") != "" : true
158+
# error_message = "When requesting a pre-setup instance, REALM, ACCESS_TOKEN and RUM_TOKEN are required and cannot be null/empty"
159+
# }
160+
# precondition {
161+
# # if access_token and realm cannot be empty.
162+
# condition = local.access_token != "" && local.realm != ""
163+
# error_message = "REALM and ACCESS_TOKEN are required and cannot be null/empty."
164+
# }
166165
}
167166
}

local-hosting/multipass/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
output "instance_details" {
22
value = data.multipass_instance.ubuntu.*
3+
}
4+
5+
# Outputs for debugging purposes
6+
output "swipe_id" {
7+
description = "SWiPE ID"
8+
value = var.swipe_id
9+
sensitive = false
10+
}
11+
output "swipe_data" {
12+
description = "Complete response from Swipe API"
13+
value = local.swipe_data
14+
sensitive = false
315
}
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
# Required
2-
splunk_access_token = ""
3-
splunk_api_token = ""
4-
splunk_realm = ""
5-
6-
# Required if splunk_presetup is true, optional otherwise. See variables.tf and README.md
7-
splunk_rum_token = ""
8-
9-
# Optional - Splunk Cloud
10-
splunk_hec_url = ""
11-
splunk_hec_token = ""
12-
splunk_index = ""
2+
swipe_id = ""
3+
splunk_index = "splunk4rookies-workshop"
134

145
# Optional
156
splunk_presetup = false
@@ -21,4 +12,4 @@ pub_key = ""
2112
# Advanced
2213
wsversion = "5.90"
2314
user_data_tpl = "userdata.yaml"
24-
architecture = "amd64" # amd64 or arm64
15+
architecture = "arm64" # amd64 or arm64

0 commit comments

Comments
 (0)