Skip to content

Commit

Permalink
Fixing the code
Browse files Browse the repository at this point in the history
  • Loading branch information
TomArcherMsft committed Nov 21, 2024
1 parent f3a6207 commit cc93f81
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
13 changes: 7 additions & 6 deletions quickstart/101-app-configuration-store-kv/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Azure App Configuration

This template deploys an Azure App Configuration and a key-value pair.
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_app_configuration_key_value](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_configuration_key_value)
- [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

Expand All @@ -17,8 +18,8 @@ This template deploys an Azure App Configuration and a key-value pair.
| `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` | Key of the App Configuration key-value pair. | "" |
| `app_configuration_label` | Label of the App Configuration key-value pair. | "" |
| `app_configuration_value` | Value of the App Configuration key-value pair. | "" |
| `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
34 changes: 27 additions & 7 deletions quickstart/101-app-configuration-store-kv/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,35 @@ resource "random_string" "azurerm_app_configuration_name" {
upper = false
}

resource "azurerm_app_configuration" "example" {
name = coalesce(var.app_configuration_name, "appcfg-${random_string.azurerm_app_configuration_name.result}")
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
}

resource "azurerm_app_configuration_key_value" "example" {
configuration_store_id = azurerm_app_configuration.example.id
key = var.app_configuration_key
label = var.app_configuration_label
value = var.app_configuration_value
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
]
}
12 changes: 10 additions & 2 deletions quickstart/101-app-configuration-store-kv/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ output "resource_group_name" {
}

output "app_configuration_name" {
value = azurerm_app_configuration.example.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_value.example.key
value = azurerm_app_configuration_key.test.value
}
12 changes: 6 additions & 6 deletions quickstart/101-app-configuration-store-kv/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ variable "app_configuration_name" {
default = ""
}

variable "app_configuration_key" {
variable "app_configuration_key_name" {
type = string
description = "Key of the App Configuration key-value pair."
description = "The name of the App Configuration key. The value will be randomly generated if blank."
default = ""
}

variable "app_configuration_label" {
variable "app_configuration_key_label" {
type = string
description = "Label of the App Configuration key-value pair."
description = "The label of the App Configuration key."
default = ""
}

variable "app_configuration_value" {
variable "app_configuration_key_value" {
type = string
description = "Value of the App Configuration key-value pair."
description = "The value of the App Configuration key."
default = ""
}

0 comments on commit cc93f81

Please sign in to comment.