diff --git a/quickstart/101-azure-api-management-create/main.tf b/quickstart/101-azure-api-management-create/main.tf new file mode 100644 index 00000000..5b9cd598 --- /dev/null +++ b/quickstart/101-azure-api-management-create/main.tf @@ -0,0 +1,25 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + name = random_pet.rg_name.id + location = var.resource_group_location +} + +resource "random_string" "azurerm_api_management_name" { + length = 13 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_api_management" "api" { + name = "apiservice${random_string.azurerm_api_management_name.result}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + publisher_email = var.publisher_email + publisher_name = var.publisher_name + sku_name = "${var.sku}_${var.sku_count}" +} diff --git a/quickstart/101-azure-api-management-create/outputs.tf b/quickstart/101-azure-api-management-create/outputs.tf new file mode 100644 index 00000000..71f8dc16 --- /dev/null +++ b/quickstart/101-azure-api-management-create/outputs.tf @@ -0,0 +1,7 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "api_management_service_name" { + value = azurerm_api_management.api.name +} diff --git a/quickstart/101-azure-api-management-create/providers.tf b/quickstart/101-azure-api-management-create/providers.tf new file mode 100644 index 00000000..4fd5f6ba --- /dev/null +++ b/quickstart/101-azure-api-management-create/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_version = ">=1.0" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-azure-api-management-create/readme.md b/quickstart/101-azure-api-management-create/readme.md new file mode 100644 index 00000000..eddc6dfd --- /dev/null +++ b/quickstart/101-azure-api-management-create/readme.md @@ -0,0 +1,21 @@ +# Azure API Management service + +This template deploys an Azure API Management service. + +## Terraform resource types + +- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) +- [azurerm_api_management](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management) + +## Variables + +| Name | Description | Default | +|-|-|-| +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | eastus | +| `publisher_email` | Email address of the owner of the service. | test@contoso.com | +| `publisher_name` | Name of the owner of the service. | publisher | +| `sku` | Pricing tier of this API Management service | Developer | +| `sku_count` | Instance size of this API Management service. | 1 | diff --git a/quickstart/101-azure-api-management-create/variables.tf b/quickstart/101-azure-api-management-create/variables.tf new file mode 100644 index 00000000..08e6455f --- /dev/null +++ b/quickstart/101-azure-api-management-create/variables.tf @@ -0,0 +1,51 @@ +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location for all resources." +} + +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "publisher_email" { + default = "test@contoso.com" + description = "The email address of the owner of the service" + type = string + validation { + condition = length(var.publisher_email) > 0 + error_message = "The publisher_email must contain at least one character." + } +} + +variable "publisher_name" { + default = "publisher" + description = "The name of the owner of the service" + type = string + validation { + condition = length(var.publisher_name) > 0 + error_message = "The publisher_name must contain at least one character." + } +} + +variable "sku" { + description = "The pricing tier of this API Management service" + default = "Developer" + type = string + validation { + condition = contains(["Developer", "Standard", "Premium"], var.sku) + error_message = "The sku must be one of the following: Developer, Standard, Premium." + } +} + +variable "sku_count" { + description = "The instance size of this API Management service." + default = 1 + type = number + validation { + condition = contains([1, 2], var.sku_count) + error_message = "The sku_count must be one of the following: 1, 2." + } +}