Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_app_service_plan is deprecated and we should use azurerm_service_plan #1958

Merged
merged 12 commits into from
Jun 6, 2022
15 changes: 5 additions & 10 deletions templates/core/terraform/api-webapp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,22 @@ locals {
version = replace(replace(replace(data.local_file.api_app_version.content, "__version__ = \"", ""), "\"", ""), "\n", "")
}

resource "azurerm_app_service_plan" "core" {
resource "azurerm_service_plan" "core" {
name = "plan-${var.tre_id}"
resource_group_name = azurerm_resource_group.core.name
location = azurerm_resource_group.core.location
kind = "linux"
reserved = true
os_type = "Linux"
sku_name = var.api_app_service_plan_sku_size
tags = local.tre_core_tags
worker_count = 1
lifecycle { ignore_changes = [tags] }

sku {
tier = var.api_app_service_plan_sku_tier
capacity = 1
size = var.api_app_service_plan_sku_size
}
}

resource "azurerm_app_service" "api" {
name = "api-${var.tre_id}"
resource_group_name = azurerm_resource_group.core.name
location = azurerm_resource_group.core.location
app_service_plan_id = azurerm_app_service_plan.core.id
app_service_plan_id = azurerm_service_plan.core.id
https_only = true
key_vault_reference_identity_id = azurerm_user_assigned_identity.id.id
tags = local.tre_core_tags
Expand Down
23 changes: 16 additions & 7 deletions templates/core/terraform/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@ set -o pipefail
set -o nounset
# set -o xtrace

# This variables are loaded in for us
# shellcheck disable=SC2154
export TF_VAR_docker_registry_server="$TF_VAR_acr_name.azurecr.io"
export TF_VAR_docker_registry_username=$TF_VAR_acr_name
export TF_VAR_docker_registry_password=$(az acr credential show --name ${TF_VAR_acr_name} --query passwords[0].value -o tsv | sed 's/"//g')
export TF_VAR_docker_registry_username="${TF_VAR_acr_name}"
TF_VAR_docker_registry_password=$(az acr credential show --name "${TF_VAR_acr_name}" --query passwords[0].value -o tsv | sed 's/"//g')
export TF_VAR_docker_registry_password

# This is where we can migrate any Terraform before we plan and apply
# For instance deprecated Terraform resources
./migrate.sh

PLAN_FILE="tfplan$$"
TS=$(date +"%s")
LOG_FILE="${TS}-tre-core.log"

# This variables are loaded in for us
# shellcheck disable=SC2154
../../../devops/scripts/terraform_wrapper.sh \
-g $TF_VAR_mgmt_resource_group_name \
-s $TF_VAR_mgmt_storage_account_name \
-n $TF_VAR_terraform_state_container_name \
-k ${TRE_ID} \
-l ${LOG_FILE} \
-g "${TF_VAR_mgmt_resource_group_name}" \
-s "${TF_VAR_mgmt_storage_account_name}" \
-n "${TF_VAR_terraform_state_container_name}" \
-k "${TRE_ID}" \
-l "${LOG_FILE}" \
-c "terraform plan -out ${PLAN_FILE} && \
terraform apply -input=false -auto-approve ${PLAN_FILE} && \
terraform output -json > ../tre_output.json"
35 changes: 35 additions & 0 deletions templates/core/terraform/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace

# This variables are loaded in for us
# shellcheck disable=SC2154
terraform init -input=false -backend=true -reconfigure -upgrade \
-backend-config="resource_group_name=${TF_VAR_mgmt_resource_group_name}" \
-backend-config="storage_account_name=${TF_VAR_mgmt_storage_account_name}" \
-backend-config="container_name=${TF_VAR_terraform_state_container_name}" \
-backend-config="key=${TRE_ID}"

echo "*** Migrating TF Resources ***"
# 1. Grab the Resource ID
# 2. Delete the old resource from state
# 3. Import the new resource in using the Azure Resource ID

# azurerm_app_service_plan -> azurerm_service_plan
core_app_service_plan_id=$(terraform show -json | jq -r '.values.root_module.resources[] | select(.address=="azurerm_app_service_plan.core") | .values.id' || null)
if [ -n "${core_app_service_plan_id}" ]; then
echo "Migrating ${core_app_service_plan_id}"
terraform state rm azurerm_app_service_plan.core
terraform import azurerm_service_plan.core "${core_app_service_plan_id}"
fi

# azurerm_app_service -> azurerm_linux_web_app
api_app_service_id=$(terraform show -json | jq -r '.values.root_module.resources[] | select(.address=="azurerm_app_service.api") | .values.id' || null)
if [ -n "${api_app_service_id}" ]; then
echo "Migrating ${api_app_service_id}. (Phase 2)"
#terraform state rm azurerm_app_service.api
#terraform import azurerm_linux_web_app.api "${api_app_service_id}"
fi
5 changes: 0 additions & 5 deletions templates/core/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ variable "api_image_repository" {
default = "microsoft/azuretre/api"
}

variable "api_app_service_plan_sku_tier" {
type = string
default = "PremiumV3"
}

variable "api_app_service_plan_sku_size" {
type = string
default = "P1v3"
Expand Down
2 changes: 1 addition & 1 deletion templates/shared_services/sonatype-nexus/terraform/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ data "azurerm_log_analytics_workspace" "tre" {
resource_group_name = local.core_resource_group_name
}

data "azurerm_app_service_plan" "core" {
data "azurerm_service_plan" "core" {
name = "plan-${var.tre_id}"
resource_group_name = local.core_resource_group_name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "azurerm_app_service" "nexus" {
name = "nexus-${var.tre_id}"
resource_group_name = local.core_resource_group_name
location = data.azurerm_resource_group.rg.location
app_service_plan_id = data.azurerm_app_service_plan.core.id
app_service_plan_id = data.azurerm_service_plan.core.id
https_only = true

app_settings = {
Expand Down