diff --git a/init-cfg.tmpl b/init-cfg.tmpl new file mode 100644 index 0000000..baa7d7e --- /dev/null +++ b/init-cfg.tmpl @@ -0,0 +1,12 @@ +type=dhcp-client +hostname=${hostname} +panorama-server=${panorama-server} +panorama-server-2=${panorama-server2} +tplname=${tplname} +dgname=${dgname} +vm-auth-key=${vm-auth-key} +op-command-modes=${op-command-modes} +dhcp-send-hostname=yes +dhcp-send-client-id=yes +dhcp-accept-server-hostname=yes +dhcp-accept-server-domain=yes \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..a455b88 --- /dev/null +++ b/main.tf @@ -0,0 +1,81 @@ +############################################################################################ +# Copyright 2020 Palo Alto Networks. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################################ + +provider "azurerm" { + subscription_id = var.azure_subscription_id + tenant_id = var.azure_tenant_id + client_id = var.azure_client_id + client_secret = var.azure_client_secret +} + +resource "random_id" "suffix" { + byte_length = 2 +} + +resource "azurerm_storage_account" "bootstrap-storage-acct" { + name = "bootstrap-storage-acct-${random_id.suffix.dec}" + resource_group_name = var.azure_resource_group + location = var.azure_location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_share" "bootstrap-storage-share" { + name = "bootstrap-storage-share-${random_id.suffix.dec}" + storage_account_name = azurerm_storage_account.bootstrap-storage-acct.name +} + +resource "azurerm_storage_share_directory" "bootstrap_dirs" { + for_each = toset(var.bootstrap_directories) + + name = each.value + share_name = azurerm_storage_share.bootstrap-storage-share.name + storage_account_name = azurerm_storage_account.bootstrap-storage-acct.name +} + +data "template_file" "init-cfg" { + template = file("${path.module}/init-cfg.tmpl") + vars = { + "hostname" = var.hostname, + "panorama-server" = var.panorama-server, + "panorama-server2" = var.panorama-server2, + "tplname" = var.tplname, + "dgname" = var.dgname, + "dns-primary" = var.dns-primary, + "dns-secondary" = var.dns-secondary, + "vm-auth-key" = var.vm-auth-key, + "op-command-modes" = var.op-command-modes + } +} + +resource "local_file" "init-cfg-file" { + content = data.template_file.init-cfg.rendered + filename = "${path.root}/files/config/init-cfg.txt" +} + + + + +resource "local-exec" { + for_each = fileset("${path.root}/files", "**") + + name = each.value + source = "${path.root}/files/${each.value}" + bucket = google_storage_bucket.bootstrap.name + + command = "az storage file upload --share ${azurerm_storage_share.bootstrap-storage-share.name} --source ${path.root}/files/${each.value}" +} + diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..cb1f524 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,31 @@ +############################################################################################ +# Copyright 2020 Palo Alto Networks. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################################ + + +output "storage_account_name" { + value = "${azurerm_storage_account.bootstrap-storage-acct.name}" + description = "Boostrap storage account" +} + +output "access_key" { + value = "${azurerm_storage_account.bootstrap-storage-acct.primary_access_key}" + description = "Bootstrap storage account access key" +} + +output "share_name" { + value = "${azurerm_storage_share.bootstrap-storage-share.name}" + description = "Bootstrap storage share name" +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..d31e4c3 --- /dev/null +++ b/variables.tf @@ -0,0 +1,111 @@ +############################################################################################ +# Copyright 2020 Palo Alto Networks. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################################ + + +variable "azure_subscription_id" { + type = "string" + description = "Your Azure subscription ID" +} + +variable "azure_tenant_id" { + type = "string" + description = "Your Azure tenant ID" +} + +variable "azure_client_id" { + type = "string" + description = "The application client ID" +} + +variable "azure_client_secret" { + type = "string" + description = "The application client secret" +} + +variable "azure_resource_group" { + type = string + description = "The Azure resource group ID" +} + +variable "azure_location" { + type = "string" + description = "The Azure location in which to deploy" +} + +variable "bootstrap_directories" { + description = "The directories comprising the bootstrap package" + default = [ + "config/", + "content/", + "software/", + "license/", + "plugins/" + ] +} + +variable "hostname" { + default = "" + description = "The hostname of the VM-series instance" + type = string +} + +variable "panorama-server" { + default = "" + description = "The FQDN or IP address of the primary Panorama server" + type = string +} + +variable "panorama-server2" { + default = "" + description = "The FQDN or IP address of the secondary Panorama server" + type = string +} + +variable "tplname" { + default = "" + description = "The Panorama template stack name" + type = string +} + +variable "dgname" { + default = "" + description = "The Panorama device group name" + type = string +} + +variable "dns-primary" { + default = "" + description = "The IP address of the primary DNS server" + type = string +} + +variable "dns-secondary" { + default = "" + description = "The IP address of the secondary DNS server" + type = string +} + +variable "vm-auth-key" { + default = "" + description = "Virtual machine authentication key" + type = string +} + +variable "op-command-modes" { + default = "" + description = "Set jumbo-frame and/or mgmt-interface-swap" + type = string +}