diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..f26b2cf --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,26 @@ +Contribution guidelines +We're happy to accept 3rd-party contributions. Please make sure you read this document before you do any work though, as we have some expectations related to the content and quality of change sets. + +Page flows and content are created and changed depending on our findings and ideas, which are unfortunately not available unless you are working for the HMCTS Reform programme. + +Before contributing +Because of the above, any ideas on the user journeys and general service experience you may have should be first consulted with us by submitting a new issue to this repository. Ideas are always welcome, but if something is divergent or unrelated to what we're trying to achieve we won't be able to accept it. Please keep this in mind as we don't want to waste anybody's time. + +In the interest of creating a friendly collaboration environment, please read and adhere to an open source contributor's code of conduct. + +Making a contribution +After your idea has been accepted you can implement it. We don't allow direct changes to the codebase from the public, they have to go through a review first. + +Here's what you should do: + +fork this repository and clone it to your machine, +create a new branch for your change: +use the latest master to branch from, +implement the change in your branch: +if the change is non-trivial it's a good practice to split it into several logically independent units and deliver each one as a separate commit, +make sure the commit messages use proper language and accurately describe commit's content, e.g. "Unify postcode lookup elements spacing". More information on good commit messages can be found here, +test if your feature works as expected and does not break any existing features, +push the change to your GitHub fork, +submit a pull request to our repository: +ensure that the pull request and related GitHub issue reference each other. +At this point the pull request will wait for someone from our team to review. It may be accepted straight away, or we may ask you to make some additional amendments before incorporating it into the main branch. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..a8321b5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,3 @@ +What would you like to change? +How do you think that would improve the project? +If this entry is related to a bug, please provide the steps to reproduce it \ No newline at end of file diff --git a/.github/PULLREQUEST_TEMPLATE.md b/.github/PULLREQUEST_TEMPLATE.md new file mode 100644 index 0000000..9ff8de6 --- /dev/null +++ b/.github/PULLREQUEST_TEMPLATE.md @@ -0,0 +1,3 @@ +Resolves # . (This is applicable only if this pull request relates to a GitHub issue, delete the line otherwise) + +Notes: * * * \ No newline at end of file diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 0000000..ee978ac --- /dev/null +++ b/.github/workflows/terraform.yml @@ -0,0 +1,39 @@ +name: 'Terraform' + +on: + pull_request: + branches: + - master + +env: + TF_VERSION: 0.12.29 + +jobs: + terraform: + name: 'terraform' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + terraform_version: ${{ env.TF_VERSION }} + + - name: Setup providers configuration + shell: bash + run: | + cat << EOF > provider.tf + provider "azurerm" { + features {} + } + EOF + - name: Terraform Init + run: terraform init + + - name: Terraform format + run: terraform fmt -check + + - name: Terraform validate + run: terraform validate \ No newline at end of file diff --git a/README.md b/README.md index b6d1ba1..cae258b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,38 @@ # terraform-module-servicebus-subscription A Terraform module for creating Azure Service Bus subscription +Refer to the following link for a detailed explanation of the Azure Service Bus topic. + +[Azure Service Bus Subscription](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-queues-topics-subscriptions)
+ +## Usage + +The following example shows how to use the module to create an Azure Service Bus topic. + +```terraform +module "servicebus-subscription" { + source = "git@github.com:hmcts/terraform-module-servicebus-subscription?ref=servicebus_subscription_tf" + name = local.subscription_name + namespace_name = module.servicebus-namespace.name + topic_name = module.servicebus-topic.name + resource_group_name = local.resource_group_name +} +``` + +## Variables + +### Configuration + +The following parameters are required by this module + +- `name` the name of the ServiceBus namespace. +- `resource_group_name` the name of the resource group in which to create the ServiceBus namespace. +- `namespace_name` the name of the service bus namespace in which the topic must be created. +- `topic_name` the name of the service bus topic in which the subscription must be created. + +The following parameters are optional + +- `max_delivery_count` the maximum number of deliveries. Default is 10. +- `lock_duration` the lock duration for the subscription as an ISO 8601 duration. Default is PT1M. +- `forward_to` the name of a Queue or Topic to automatically forward messages to. +- `forward_dead_lettered_messages_to` the name of a Queue or Topic to automatically forward Dead Letter messages to. \ No newline at end of file diff --git a/main.tf b/main.tf index 186476f..5749a48 100644 --- a/main.tf +++ b/main.tf @@ -1,22 +1,18 @@ -# ARM template for Service Bus subscription -data "template_file" "subscription_template" { - template = "${file("${path.module}/template/subscription_template.json")}" -} +resource "azurerm_servicebus_subscription" "servicebus_subscription" { + name = var.name + resource_group_name = var.resource_group_name + namespace_name = var.namespace_name + topic_name = var.topic_name -# Create Azure Service Bus subscription -resource "azurerm_template_deployment" "subscription" { - template_body = "${data.template_file.subscription_template.rendered}" - name = "${var.name}" - deployment_mode = "Incremental" - resource_group_name = "${var.resource_group_name}" + lock_duration = var.lock_duration + max_delivery_count = var.max_delivery_count + forward_to = var.forward_to + forward_dead_lettered_messages_to = var.forward_dead_lettered_messages_to + requiresSession = var.requires_session - parameters = { - serviceBusNamespaceName = "${var.namespace_name}" - serviceBusTopicName = "${var.topic_name}" - serviceBusSubscriptionName = "${var.name}" - lockDuration = "${var.lock_duration}" - maxDeliveryCount = "${var.max_delivery_count}" - forwardTo = "${var.forward_to}" - forwardDeadLetteredMessagesTo = "${var.forward_dead_lettered_messages_to}" - } + requires_session = var.requires_session + dead_lettering_on_message_expiration = true + enable_batched_operations = false + default_message_ttl = "P10675199DT2H48M5.4775807S" + auto_delete_on_idle = "P10675199DT2H48M5.4775807S" } diff --git a/template/subscription_template.json b/template/subscription_template.json deleted file mode 100644 index 9670dd5..0000000 --- a/template/subscription_template.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "serviceBusNamespaceName": { - "type": "string", - "metadata": { - "description": "Name of the Service Bus namespace" - } - }, - "serviceBusTopicName": { - "type": "string", - "metadata": { - "description": "Name of the Topic" - } - }, - "serviceBusSubscriptionName": { - "type": "string", - "metadata": { - "description": "Name of the Subscription" - } - }, - "lockDuration": { - "type": "string", - "metadata": { - "description": "Message lock duration (ISO-8601)" - } - }, - "maxDeliveryCount": { - "type": "string", - "metadata": { - "description": "Maximum number of attempts to deliver a message before it's sent to dead letter queue" - } - }, - "forwardTo": { - "type": "string", - "metadata": { - "description": "Topic or Queue to forwards received messages to" - } - }, - "forwardDeadLetteredMessagesTo": { - "type": "string", - "metadata": { - "description": "Topic or Queue to forwards dead lettered messages to" - } - } - }, - "variables": { - "sbVersion": "2017-04-01" - }, - "resources": [ - { - "apiVersion": "2017-04-01", - "name": "[concat(parameters('serviceBusNamespaceName'), '/', parameters('serviceBusTopicName'), '/', parameters('serviceBusSubscriptionName'))]", - "type": "Microsoft.ServiceBus/namespaces/topics/subscriptions", - "properties": { - "lockDuration": "[parameters('lockDuration')]", - "requiresSession": "false", - "defaultMessageTimeToLive": "P10675199DT2H48M5.4775807S", - "deadLetteringOnMessageExpiration": "true", - "maxDeliveryCount": "[parameters('maxDeliveryCount')]", - "enableBatchedOperations": "false", - "autoDeleteOnIdle": "P10675199DT2H48M5.4775807S", - "forwardTo" : "[if(empty(parameters('forwardTo')), json('null'), parameters('forwardTo'))]", - "forwardDeadLetteredMessagesTo" : "[if(empty(parameters('forwardDeadLetteredMessagesTo')), json('null'), parameters('forwardDeadLetteredMessagesTo'))]" - } - } - ] -} diff --git a/variables.tf b/variables.tf index 6403058..bcc1419 100644 --- a/variables.tf +++ b/variables.tf @@ -1,43 +1,49 @@ variable "name" { - type = "string" + type = string description = "Azure Service Bus subscription name" } variable "namespace_name" { - type = "string" + type = string description = "Azure Service Bus namespace" } variable "topic_name" { - type = "string" + type = string description = "Azure Service Bus topic name" } variable "resource_group_name" { - type = "string" + type = string description = "Resource group in which the Service Bus subscription should exist" } variable "max_delivery_count" { - type = "string" + type = number description = "Maximum number of attempts to deliver a message before it's sent to dead letter queue" - default = "10" + default = 10 } variable "lock_duration" { - type = "string" + type = string description = "Message lock duration (ISO-8601)" - default = "PT1M" + default = "PT1M" } variable "forward_to" { - type = "string" + type = string description = "Topic or Queue to forwards received messages to" - default = "" + default = "" } variable "forward_dead_lettered_messages_to" { - type = "string" + type = string description = "Topic or Queue to forwards dead lettered messages to" - default = "" -} \ No newline at end of file + default = "" +} + +variable "requires_session" { + type = bool + description = "A value that indicates whether the queue supports the concept of sessions" + default = false +}