Skip to content

Commit

Permalink
Get certificate ID over name
Browse files Browse the repository at this point in the history
  • Loading branch information
benchiverton committed Jul 1, 2024
1 parent ed2404b commit 99ed0fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions terraform/instance/container_apps_bind_dns/scripts/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ fi
# check if a managed cert for the domain already exists
# if it does not exist, provision one
# if it does, save its name to use for binding it later
MANAGED_CERTIFICATE_NAME=$(
MANAGED_CERTIFICATE_ID=$(
az containerapp env certificate list \
-g $CONTAINER_APP_ENV_RESOURCE_GROUP \
-n $CONTAINER_APP_ENV_NAME \
--managed-certificates-only \
--query "[?properties.subjectName=='$CUSTOM_DOMAIN'].name" \
--query "[?properties.subjectName=='$CUSTOM_DOMAIN'].id" \
--output tsv
)
if [ -z "${MANAGED_CERTIFICATE_NAME}" ]; then
MANAGED_CERTIFICATE_NAME=$(
if [ -z "${MANAGED_CERTIFICATE_ID}" ]; then
MANAGED_CERTIFICATE_ID=$(
az containerapp env certificate create \
-g $CONTAINER_APP_ENV_RESOURCE_GROUP \
-n $CONTAINER_APP_ENV_NAME \
--hostname $CUSTOM_DOMAIN \
--validation-method CNAME \
--query "name" \
--query "id" \
--output tsv
)
echo "created cert for '$CUSTOM_DOMAIN'. waiting for it to provision now..."
Expand Down Expand Up @@ -118,7 +118,7 @@ else
-n $CONTAINER_APP_NAME \
--hostname $CUSTOM_DOMAIN \
--environment $CONTAINER_APP_ENV_NAME \
--certificate $MANAGED_CERTIFICATE_NAME \
--certificate $MANAGED_CERTIFICATE_ID \
--output none
echo "finished binding. the domain is now secured and ready to use"
fi
2 changes: 2 additions & 0 deletions terraform/instance/container_apps_bind_dns/scripts/destroy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# functions below taken from: https://stackoverflow.com/a/25515370
yell() { echo "$0: $*" >&2; }
die() {
Expand Down
8 changes: 4 additions & 4 deletions terraform/instance/container_apps_bind_dns/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ variable "container_app_resource_group_name" {
type = string
}

variable "container_app_env_resource_group_name" {
description = "name of the resource group where the container app environment is deployed"
variable "container_app_env_name" {
description = "name of the container app environment name"
type = string
}

variable "container_app_env_name" {
description = "name of the container app environment name"
variable "container_app_env_resource_group_name" {
description = "name of the resource group where the container app environment is deployed"
type = string
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/instance/dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ resource "azurerm_container_app_custom_domain" "monitoring" {
module "container_apps_bind_dns" {
source = "./container_apps_bind_dns"
container_app_resource_group_name = azurerm_resource_group.instance.name
container_app_env_resource_group_name = data.azurerm_container_app_environment.apps.resource_group_name
container_app_env_name = data.azurerm_container_app_environment.apps.name
container_app_env_resource_group_name = data.azurerm_container_app_environment.apps.resource_group_name
services = [
{
key = "api",
Expand Down

0 comments on commit 99ed0fb

Please sign in to comment.