diff --git a/examples/azure-servicebus-create-topic-and-subscription/README.md b/examples/azure-servicebus-create-topic-and-subscription/README.md new file mode 100644 index 000000000..6234b7ccf --- /dev/null +++ b/examples/azure-servicebus-create-topic-and-subscription/README.md @@ -0,0 +1,22 @@ +# 201 Create a Servicebus with Topic and Subscription + +For information about using this template, see [Create a Service Bus namespace with Topic and Subscription using an ARM template](http://azure.microsoft.com/documentation/articles/service-bus-resource-manager-namespace-topic/). + +## main.tf +The `main.tf` file contains the actual resources that will be deployed. It also contains the Azure Resource Group definition and any defined variables. + +## outputs.tf +This data is outputted when `terraform apply` is called, and can be queried using the `terraform output` command. + +## provider.tf +Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. + +## terraform.tfvars +If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. + +If you are committing this template to source control, please insure that you add this file to your `.gitignore` file. + +## variables.tf +The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. + +![graph](/examples/azure-servicebus-create-topic-and-subscription/graph.png) \ No newline at end of file diff --git a/examples/azure-servicebus-create-topic-and-subscription/deploy.ci.sh b/examples/azure-servicebus-create-topic-and-subscription/deploy.ci.sh new file mode 100755 index 000000000..ef99ef866 --- /dev/null +++ b/examples/azure-servicebus-create-topic-and-subscription/deploy.ci.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -o errexit -o nounset + +docker run --rm -it \ + -e ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID \ + -v $(pwd):/data \ + --workdir=/data \ + --entrypoint "/bin/sh" \ + hashicorp/terraform:light \ + -c "/bin/terraform get; \ + /bin/terraform validate; \ + /bin/terraform plan -out=out.tfplan -var unique=$KEY -var resource_group=$KEY; \ + /bin/terraform apply out.tfplan; \ + /bin/terraform show;" + + +# cleanup deployed azure resources via terraform +docker run --rm -it \ + -e ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID \ + -v $(pwd):/data \ + --workdir=/data \ + --entrypoint "/bin/sh" \ + hashicorp/terraform:light \ + -c "/bin/terraform destroy -force -var unique=$KEY -var resource_group=$KEY;" \ No newline at end of file diff --git a/examples/azure-servicebus-create-topic-and-subscription/deploy.mac.sh b/examples/azure-servicebus-create-topic-and-subscription/deploy.mac.sh new file mode 100755 index 000000000..9c6563f07 --- /dev/null +++ b/examples/azure-servicebus-create-topic-and-subscription/deploy.mac.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -o errexit -o nounset + +if docker -v; then + + # generate a unique string for CI deployment + export KEY=$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-z' | head -c 12) + export PASSWORD=$KEY$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'A-Z' | head -c 2)$(cat /dev/urandom | env LC_CTYPE=C tr -cd '0-9' | head -c 2) + + /bin/sh ./deploy.ci.sh + +else + echo "Docker is used to run terraform commands, please install before run: https://docs.docker.com/docker-for-mac/install/" +fi diff --git a/examples/azure-servicebus-create-topic-and-subscription/graph.png b/examples/azure-servicebus-create-topic-and-subscription/graph.png new file mode 100644 index 000000000..c2292cdeb Binary files /dev/null and b/examples/azure-servicebus-create-topic-and-subscription/graph.png differ diff --git a/examples/azure-servicebus-create-topic-and-subscription/main.tf b/examples/azure-servicebus-create-topic-and-subscription/main.tf new file mode 100644 index 000000000..5aa6d4815 --- /dev/null +++ b/examples/azure-servicebus-create-topic-and-subscription/main.tf @@ -0,0 +1,37 @@ +# provider "azurerm" { +# subscription_id = "REPLACE-WITH-YOUR-SUBSCRIPTION-ID" +# client_id = "REPLACE-WITH-YOUR-CLIENT-ID" +# client_secret = "REPLACE-WITH-YOUR-CLIENT-SECRET" +# tenant_id = "REPLACE-WITH-YOUR-TENANT-ID" +# } + +resource "azurerm_resource_group" "rg" { + name = "${var.resource_group}" + location = "${var.location}" +} + +resource "azurerm_servicebus_namespace" "test" { + depends_on = ["azurerm_resource_group.rg"] + name = "${var.unique}servicebus" + location = "${var.location}" + resource_group_name = "${var.resource_group}" + sku = "standard" +} + +resource "azurerm_servicebus_topic" "test" { + name = "${var.unique}Topic" + location = "${var.location}" + resource_group_name = "${var.resource_group}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + + enable_partitioning = true +} + +resource "azurerm_servicebus_subscription" "test" { + name = "${var.unique}Subscription" + location = "${var.location}" + resource_group_name = "${var.resource_group}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + topic_name = "${azurerm_servicebus_topic.test.name}" + max_delivery_count = 1 +} diff --git a/examples/azure-servicebus-create-topic-and-subscription/outputs.tf b/examples/azure-servicebus-create-topic-and-subscription/outputs.tf new file mode 100644 index 000000000..a35fe80d2 --- /dev/null +++ b/examples/azure-servicebus-create-topic-and-subscription/outputs.tf @@ -0,0 +1,7 @@ +output "Namespace Connection String" { + value = "${azurerm_servicebus_namespace.test.default_primary_connection_string}" +} + +output "Shared Access Policy PrimaryKey" { + value = "${azurerm_servicebus_namespace.test.default_primary_key}" +} diff --git a/examples/azure-servicebus-create-topic-and-subscription/variables.tf b/examples/azure-servicebus-create-topic-and-subscription/variables.tf new file mode 100644 index 000000000..e1df4f302 --- /dev/null +++ b/examples/azure-servicebus-create-topic-and-subscription/variables.tf @@ -0,0 +1,12 @@ +variable "resource_group" { + description = "The name of the resource group in which to create the Service Bus" +} + +variable "location" { + description = "The location/region where the Service Bus is created. Changing this forces a new resource to be created." + default = "southcentralus" +} + +variable "unique" { + description = "a unique string that will be used to comprise the names of the Service Bus, Topic, and Subscription name spaces" +}