diff --git a/quickstart/101-app-configuration-store-kv/README.md b/quickstart/101-app-configuration-store-kv/README.md new file mode 100644 index 000000000..a05d80957 --- /dev/null +++ b/quickstart/101-app-configuration-store-kv/README.md @@ -0,0 +1,25 @@ +# Azure App Configuration +This template deploys an Azure App Configuration resource and a key. + +## 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_app_configuration](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_configuration) +- [azurerm_client_config](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) +- [azurerm_role_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) +- [azurerm_app_configuration_key](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_configuration_key) + +## Variables + +| Name | Description | Default value | +|-|-|-| +| `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 | +| `app_configuration_name` | Name of the App Configuration resource. The value will be randomly generated if blank. | "" | +| `app_configuration_key_name` | Name of the App Configuration key. The value will be randomly generated if blank. | "" | +| `app_configuration_key_label` | Label of the App Configuration key. | "" | +| `app_configuration_key_value` | Value of the App Configuration key. | "" | + +## Example \ No newline at end of file diff --git a/quickstart/101-app-configuration-store-kv/main.tf b/quickstart/101-app-configuration-store-kv/main.tf new file mode 100644 index 000000000..48d40dfd4 --- /dev/null +++ b/quickstart/101-app-configuration-store-kv/main.tf @@ -0,0 +1,49 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id +} + +resource "random_string" "azurerm_app_configuration_name" { + length = 13 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_app_configuration" "appconf" { + name = coalesce(var.app_configuration_name, "appconf-${random_string.azurerm_app_configuration_name.result}") + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location +} + +data "azurerm_client_config" "current" {} + +resource "azurerm_role_assignment" "appconf_dataowner" { + scope = azurerm_app_configuration.appconf.id + role_definition_name = "App Configuration Data Owner" + principal_id = data.azurerm_client_config.current.object_id +} + +resource "random_string" "azurerm_app_configuration_key_name" { + length = 13 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_app_configuration_key" "test" { + configuration_store_id = azurerm_app_configuration.appconf.id + key = coalesce(var.app_configuration_key_name, "key-${random_string.azurerm_app_configuration_key_name.result}") + label = var.app_configuration_key_label + value = var.app_configuration_key_value + + depends_on = [ + azurerm_role_assignment.appconf_dataowner + ] +} \ No newline at end of file diff --git a/quickstart/101-app-configuration-store-kv/outputs.tf b/quickstart/101-app-configuration-store-kv/outputs.tf new file mode 100644 index 000000000..4c2fef7f3 --- /dev/null +++ b/quickstart/101-app-configuration-store-kv/outputs.tf @@ -0,0 +1,19 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "app_configuration_name" { + value = azurerm_app_configuration.appconf.name +} + +output "app_configuration_key_name" { + value = azurerm_app_configuration_key.test.key +} + +output "app_configuration_key_label" { + value = azurerm_app_configuration_key.test.label +} + +output "app_configuration_key_value" { + value = azurerm_app_configuration_key.test.value +} \ No newline at end of file diff --git a/quickstart/101-app-configuration-store-kv/providers.tf b/quickstart/101-app-configuration-store-kv/providers.tf new file mode 100644 index 000000000..058b68717 --- /dev/null +++ b/quickstart/101-app-configuration-store-kv/providers.tf @@ -0,0 +1,18 @@ +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-app-configuration-store-kv/variables.tf b/quickstart/101-app-configuration-store-kv/variables.tf new file mode 100644 index 000000000..792bd777d --- /dev/null +++ b/quickstart/101-app-configuration-store-kv/variables.tf @@ -0,0 +1,35 @@ +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 "resource_group_location" { + type = string + default = "eastus" + description = "Location of the resource group." +} + +variable "app_configuration_name" { + type = string + description = "The name of the App Configuration resource. The value will be randomly generated if blank." + default = "" +} + +variable "app_configuration_key_name" { + type = string + description = "The name of the App Configuration key. The value will be randomly generated if blank." + default = "" +} + +variable "app_configuration_key_label" { + type = string + description = "The label of the App Configuration key." + default = "" +} + +variable "app_configuration_key_value" { + type = string + description = "The value of the App Configuration key." + default = "" +} \ No newline at end of file