Skip to content

Commit

Permalink
fully automated splunk + databricks app
Browse files Browse the repository at this point in the history
  • Loading branch information
hwang-db committed Jun 29, 2022
1 parent c28e662 commit 7e53ac5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 46 deletions.
44 changes: 43 additions & 1 deletion adb-splunk/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,51 @@ resource "azurerm_resource_group" "this" {
tags = local.tags
}

// step 1 create storage account and container
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
}

// step 2 create local file of scripts
resource "local_file" "setupscript" {
content = <<EOT
#! /bin/bash
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://${module.adls_content.storage_name}.blob.core.windows.net/${module.adls_content.container_name}/databricks-add-on-for-splunk_110.tgz" --name splunk splunk/splunk:latest
EOT
filename = "splunk_setup.sh"
file_permission = "0777" // default value 0777

depends_on = [
module.adls_content
]
}

// step 3 upload scripts and artifacts onto container
resource "azurerm_storage_blob" "file1" {
name = "splunk_setup.sh"
storage_account_name = module.adls_content.storage_name
storage_container_name = module.adls_content.container_name
type = "Block"
source = "${path.root}/splunk_setup.sh"

depends_on = [
local_file.setupscript
]
}

resource "azurerm_storage_blob" "splunk_databricks_app_file" {
name = "databricks-add-on-for-splunk_110.tgz"
storage_account_name = module.adls_content.storage_name
storage_container_name = module.adls_content.container_name
type = "Block"
source = "${path.root}/artifacts/databricks-add-on-for-splunk_110.tgz"

depends_on = [
local_file.setupscript
]
}
8 changes: 0 additions & 8 deletions adb-splunk/modules/adls_content/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,3 @@ resource "azurerm_storage_container" "container1" {
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
}
8 changes: 6 additions & 2 deletions adb-splunk/modules/adls_content/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "file_url" {
value = azurerm_storage_blob.file1.url
output "storage_name" {
value = azurerm_storage_account.personaldropbox.name
}

output "container_name" {
value = azurerm_storage_container.container1.name
}
5 changes: 0 additions & 5 deletions adb-splunk/modules/adls_content/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ variable "rg" {
type = string
}

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

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

output "file_url" {
value = module.adls_content.file_url
}
9 changes: 5 additions & 4 deletions adb-splunk/splunk_setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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
#! /bin/bash
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://adlsw2fpvu.blob.core.windows.net/cnt1/databricks-add-on-for-splunk_110.tgz" --name splunk splunk/splunk:latest
30 changes: 8 additions & 22 deletions adb-splunk/splunkvm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ resource "azurerm_linux_virtual_machine" "example" {

depends_on = [
local_file.private_key,
module.adls_content
local_file.setupscript,
module.adls_content,
azurerm_storage_blob.file1,
azurerm_storage_blob.splunk_databricks_app_file
]
}

Expand All @@ -73,31 +76,14 @@ resource "azurerm_virtual_machine_extension" "splunksetupagent" {

settings = <<SETTINGS
{
"fileUris": ["${module.adls_content.file_url}"],
"commandToExecute": "sh splunk_setup.sh"
"fileUris": ["https://${module.adls_content.storage_name}.blob.core.windows.net/${module.adls_content.container_name}/splunk_setup.sh"],
"commandToExecute": "sudo sh splunk_setup.sh"
}
SETTINGS

depends_on = [
azurerm_linux_virtual_machine.example,
module.adls_content
azurerm_storage_blob.file1,
azurerm_storage_blob.splunk_databricks_app_file
]
}


/*
resource "null_resource" "test_null" {
triggers = {
always_run = "${timestamp()}"
}
provisioner "local-exec" {
command = <<-EOT
terraform output -raw tls_private_key > ssh_private.pem
chmod 400 ssh_private.pem
EOT
}
depends_on = [
tls_private_key.splunk_ssh,
]
}
*/

0 comments on commit 7e53ac5

Please sign in to comment.