Skip to content

Commit

Permalink
mvp complete for splunk + app setup
Browse files Browse the repository at this point in the history
  • Loading branch information
hwang-db committed Jun 29, 2022
1 parent 8b7a4b2 commit c28e662
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 28 deletions.
55 changes: 28 additions & 27 deletions adb-splunk/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions adb-splunk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Splunk quick demo

http://20.212.33.56:8000
Binary file not shown.
7 changes: 7 additions & 0 deletions adb-splunk/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ resource "azurerm_resource_group" "this" {
location = local.location
tags = local.tags
}

module "adls_content" {
source = "./modules/adls_content"
rg = azurerm_resource_group.this.name
storage_account_location = var.rglocation
local_file_path = "${path.root}/splunk_setup.sh" // local file to be uploaded to adls
}
5 changes: 5 additions & 0 deletions adb-splunk/modules/adls_content/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### adls_content module

This module will create a storage account in specified rg, and create a container, and put a designated local file into the container.

Ouput will be URL to that file in the container.
48 changes: 48 additions & 0 deletions adb-splunk/modules/adls_content/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=3.0.0"
}
random = {
source = "hashicorp/random"
version = ">=3.3.2"
}
local = {
source = "hashicorp/local"
version = ">=2.2.3"
}
}
}

resource "random_string" "naming" {
special = false
upper = false
length = 6
}

locals {
storage_account_name = join("", ["adls", "${random_string.naming.result}"]) // must not have special chars
}

resource "azurerm_storage_account" "personaldropbox" {
name = local.storage_account_name
resource_group_name = var.rg
location = var.storage_account_location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_storage_container" "container1" {
name = "cnt1"
storage_account_name = azurerm_storage_account.personaldropbox.name
container_access_type = "container" // for anonymous read container from public
}

resource "azurerm_storage_blob" "file1" {
name = "splunk_setup.sh"
storage_account_name = azurerm_storage_account.personaldropbox.name
storage_container_name = azurerm_storage_container.container1.name
type = "Block"
source = var.local_file_path
}
3 changes: 3 additions & 0 deletions adb-splunk/modules/adls_content/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "file_url" {
value = azurerm_storage_blob.file1.url
}
13 changes: 13 additions & 0 deletions adb-splunk/modules/adls_content/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "rg" {
type = string
}

variable "local_file_path" {
type = string
default = ""
}

variable "storage_account_location" {
type = string
default = "southeastasia"
}
4 changes: 4 additions & 0 deletions adb-splunk/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ output "azure_region" {
output "resource_group" {
value = azurerm_resource_group.this.name
}

output "file_url" {
value = module.adls_content.file_url
}
4 changes: 4 additions & 0 deletions adb-splunk/splunk_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sudo apt update
sudo apt install docker.io -y
sudo apt install docker-compose -y
sudo docker run -d -p 8000:8000 -e "SPLUNK_START_ARGS=--accept-license" -e "SPLUNK_PASSWORD=password" -e "SPLUNK_APPS_URL=https://jlaw-public-db.s3.ap-southeast-1.amazonaws.com/databricks-add-on-for-splunk_110.tgz" --name splunk splunk/splunk:latest
26 changes: 26 additions & 0 deletions adb-splunk/splunkvm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,34 @@ resource "azurerm_linux_virtual_machine" "example" {
sku = "20_04-lts-gen2"
version = "latest"
}

depends_on = [
local_file.private_key,
module.adls_content
]
}

resource "azurerm_virtual_machine_extension" "splunksetupagent" {
name = "hwangagent"
virtual_machine_id = azurerm_linux_virtual_machine.example.id
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.1"

settings = <<SETTINGS
{
"fileUris": ["${module.adls_content.file_url}"],
"commandToExecute": "sh splunk_setup.sh"
}
SETTINGS

depends_on = [
azurerm_linux_virtual_machine.example,
module.adls_content
]
}


/*
resource "null_resource" "test_null" {
triggers = {
Expand Down
2 changes: 1 addition & 1 deletion adb-splunk/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
required_providers {
databricks = {
source = "databricks/databricks"
source = "databricks/databricks"
version = ">=0.5.1"
}

Expand Down

0 comments on commit c28e662

Please sign in to comment.