Skip to content

Commit 6a6eb8d

Browse files
committed
replace original
1 parent e0b2e74 commit 6a6eb8d

File tree

1 file changed

+0
-103
lines changed

1 file changed

+0
-103
lines changed

articles/application-gateway/renew-certificates.md

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -71,110 +71,7 @@ az network application-gateway ssl-cert update \
7171
--cert-password "<password>"
7272
```
7373

74-
### Terraform
7574

76-
If you're using Terraform to manage the application gateway, the Azure Terraform Key Vault data source retrieves the complete key vault URI, which includes the version of the secrets. To enable automatic rotation of the certificate to a new version, the secret needs to be without a specific version. In the following Terraform code, the data source **azurerm_key_vault_secret** fetches the Key Vault secret ID and includes the version of the secret in the complete Keyvault URL.
77-
78-
```Terraform
79-
data "azurerm_key_vault_secret" "vault" {
80-
name = "byte-cloud"
81-
key_vault_id = "<resource-id-key-vault>"
82-
}
83-
```
84-
85-
Definitions:
86-
87-
| Entry | Description |
88-
| --- | --- |
89-
| **data** | Indicates that you are retrieving information from an existing resource rather than creating a new one. |
90-
| **azurerm_key_vault_secret** | Specifies the type or kind of data source, in this case, it's fetching information about a secret from an Azure Key Vault. |
91-
| **vault** | The name of this particular instance of the azurerm_key_vault_secret data source. Refer to this name when using the output from this data source in your Terraform configuration. |
92-
| **name** | The name of the certificate stored in Keyvault. |
93-
94-
The data source **azurerm_key_vault_secret** is used within the `**ssl_certificate**` block under the application gateway section.
95-
96-
The following Terraform code adds an SSL certificate pointed to the secret version of the certificate:
97-
98-
```Terraform
99-
data "azurerm_key_vault_secret" "vault" {
100-
name = "<certificate-name>"
101-
key_vault_id = "<resource-id-key-vault>"
102-
}
103-
resource "azurerm_application_gateway" "main" {
104-
name = "myAppGateway"
105-
resource_group_name = data.azurerm_resource_group.rg.name
106-
location = data.azurerm_resource_group.rg.location
107-
sku {
108-
name = "Standard_v2"
109-
tier = "Standard_v2"
110-
capacity = 1
111-
}
112-
}
113-
identity {
114-
type = "UserAssigned"
115-
identity_ids = [data.azurerm_user_assigned_identity.appgw_identity.id]
116-
}
117-
118-
ssl_certificate {
119-
name = "<desired-ssl-certificate-name>"
120-
// Reference the Key Vault secret ID
121-
`#096DA`key_vault_secret_id = data.azurerm_key_vault_secret.vault.id`#096DA`
122-
}
123-
```
124-
125-
**key_vault_secret_id** is the certificate object stored in Azure KeyVault.
126-
127-
Next, navigate to Application gateway listener settings and and select the **Listener TLS Certificates Preview** tab.
128-
129-
![navigateListener](media/renew-certificate/listener-navigation.png)
130-
![oldsslcert](media/renew-certificate/oldsslcertlink.png)
131-
132-
> [!NOTE]
133-
> * The certificate added to the application gateway is tied to a **secret version**.
134-
> * Renewing the certificate in **KeyVault** doesn't automatically make the application gateway listener select the updated certificate. To reflect the changes, the certificate in the application gateway must be manually updated.
135-
136-
To add versionless keyvault certificates, you can use the Terraform "**replace**" function. By using this function, you can replace the entire KeyVault URL, which includes the secret version, with just the secret name, excluding the version.
137-
138-
- Modify the existing "**ssl_certificate**" block under the application gateway block of the Terraform to use the replace function.
139-
140-
```Terraform
141-
resource "azurerm_application_gateway" "main" {
142-
name = "myAppGateway"
143-
resource_group_name = data.azurerm_resource_group.rg.name
144-
location = data.azurerm_resource_group.rg.location
145-
sku {
146-
name = "Standard_v2"
147-
tier = "Standard_v2"
148-
capacity = 1
149-
}
150-
}
151-
identity {
152-
type = "UserAssigned"
153-
identity_ids = [data.azurerm_user_assigned_identity.appgw_identity.id]
154-
}
155-
156-
ssl_certificate {
157-
name = "afdpremium-agw-ssl-certificate"
158-
// Reference the Key Vault secret ID
159-
<span style="background-color: yellow; color: black">key_vault_secret_id = replace(data.azurerm_key_vault_secret.vault.id, "/secrets/(.*)/[^/]+/", "secrets/$1")</span>
160-
}
161-
```
162-
163-
- The same data source "**data.azurerm_key_vault_secret.vault.id**" is used here, but the data source is used with the replace function.
164-
- You can compare the value in the data source “**data.azurerm_key_vault_secret.vault.id**” with regex “/secrets/(.*)/[^/]+/",” and then use /secrets/group1.
165-
166-
The Terraform replace function takes three arguments:
167-
- replace(string, substring, replacement).
168-
169-
In this case, **string** is the full URL stored in the data source **data.azurerm_key_vault_secret.vault.id** , substring is **/secrets/(.*)/[^/]+/**, and replacement is **/secrets/$1**.
170-
171-
**For-example**:
172-
173-
- **secret_value_old** = https://dummy.vault.azure.net/secrets/afdpremium/5cd21fe4d7934a82b187ffcaa86ae3f6 [before replace function]
174-
175-
- **secret_value_new**: https://dummy.vault.azure.net/afdpremium [after replace function]
176-
177-
Add a forward slash “**/**” in Terraform regex, or it will not work. This is because Terraform uses forward slashes as separators in certain syntax constructs to organize resources and data sources hierarchically.
17875

17976
## Next steps
18077

0 commit comments

Comments
 (0)