diff --git a/.github/workflows/deploy-env.yaml b/.github/workflows/deploy-env.yaml index 8f6b146..28c0481 100644 --- a/.github/workflows/deploy-env.yaml +++ b/.github/workflows/deploy-env.yaml @@ -1,6 +1,6 @@ on: push: - branches: [ "feat/azure_setup" ] + branches: [ "feat/terraform" ] jobs: @@ -22,9 +22,29 @@ jobs: creds: ${{ secrets.AZURE_CREDENTIALS }} enable-AzPSSession: true - - name: Azure CLI script + - name: Create TF State dependencies uses: azure/cli@v2 with: azcliversion: latest inlineScript: | - az account show \ No newline at end of file + az group create --name s186${{ var.ENVIRONMENT_PREFIX }}cl-tfstate --location westeurope + + az storage account create --name s186${{ var.ENVIRONMENT_PREFIX }}cltfstate --resource-group s186${{ var.ENVIRONMENT_PREFIX }}cl-tfstate --location westeurope --sku Standard_LRS + + az storage container create --name tfstate --account-name s186${{ var.ENVIRONMENT_PREFIX }}cltfstate + + - name: 'Terraform Init' + id: terraform_init + working-directory: ./src/infrastructure/terraform + run: terraform init -backend-config="resource_group_name=s186${{ var.ENVIRONMENT_PREFIX }}cl-tfstate" -backend-config="storage_account_name=s186${{ var.ENVIRONMENT_PREFIX }}cltfstate" -backend-config="container_name=tfstate" -backend-config="key=terraform.tfstate" + + - name: 'Terraform Plan' + id: terraform_plan + working-directory: ./src/infrastructure/terraform + run: terraform plan -out plan.plan + + - name: 'Terraform Apply' + id: terraform_apply + working-directory: ./src/infrastructure/terraform + run: terraform apply plan.plan + diff --git a/src/infrastructure/terraform/locals.tf b/src/infrastructure/terraform/locals.tf index 7001fbe..b2b9ba3 100644 --- a/src/infrastructure/terraform/locals.tf +++ b/src/infrastructure/terraform/locals.tf @@ -5,5 +5,6 @@ locals { "Service" = "Newly onboarded" "Service offering" = "Design operations" } - service_prefix = "s186" + service_prefix = "s186${var.environment_prefix}-cl" + location = "westeurope" } \ No newline at end of file diff --git a/src/infrastructure/terraform/main.tf b/src/infrastructure/terraform/main.tf index e69de29..07978a6 100644 --- a/src/infrastructure/terraform/main.tf +++ b/src/infrastructure/terraform/main.tf @@ -0,0 +1,5 @@ +resource "azurerm_resource_group" "core-rg" { + name = "${local.service_prefix}-core-rg" + location = local.location + tags = local.common_tags +} \ No newline at end of file diff --git a/src/infrastructure/terraform/variables.tf b/src/infrastructure/terraform/variables.tf index 2654d28..f095666 100644 --- a/src/infrastructure/terraform/variables.tf +++ b/src/infrastructure/terraform/variables.tf @@ -4,3 +4,8 @@ variable "cip_environment" { default = "Dev" } +variable "environment_prefix" { + description = "Environment prefix (e.g. d01)" + type = string +} +