Skip to content

Commit

Permalink
Adding app insights resource
Browse files Browse the repository at this point in the history
  • Loading branch information
frasermolyneux committed Dec 8, 2023
1 parent 8ce3f56 commit d95cb79
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "terraform"
assignees: ["frasermolyneux"]
directory: "/terraform"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
assignees: ["frasermolyneux"]
directory: "/"
schedule:
interval: "daily"
22 changes: 22 additions & 0 deletions .github/workflows/dependabot-automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Dependabot Auto-Merge
on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
28 changes: 28 additions & 0 deletions .github/workflows/destroy-development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Destroy Development

on:
workflow_dispatch:

permissions:
id-token: write # This is required for Az CLI Login
contents: read # This is required for actions/checkout

jobs:
terraform-destroy-dev:
environment: Development
runs-on: ubuntu-latest

concurrency:
group: ${{ github.repository }}-dev

steps:
- uses: actions/checkout@v4

- uses: frasermolyneux/actions/terraform-destroy@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/dev.tfvars"
terraform-backend-file: "backends/dev.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
32 changes: 32 additions & 0 deletions .github/workflows/feature-development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Feature Development

on:
workflow_dispatch:
push:
branches:
- "feature/*"

permissions:
id-token: write # This is required for Az CLI Login
contents: read # This is required for actions/checkout

jobs:
terraform-plan-and-apply-dev:
environment: Development
runs-on: ubuntu-latest

concurrency:
group: ${{ github.repository }}-dev

steps:
- uses: actions/checkout@v4

- uses: frasermolyneux/actions/terraform-plan-and-apply@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/dev.tfvars"
terraform-backend-file: "backends/dev.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

61 changes: 61 additions & 0 deletions .github/workflows/pull-request-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Pull Request Validation

on:
workflow_dispatch:
pull_request:
branches:
- main

permissions:
id-token: write # This is required for Az CLI Login
contents: read # This is required for actions/checkout

jobs:
dependency-review:
runs-on: ubuntu-latest

steps:
- name: "Checkout Repository"
uses: actions/checkout@v4

- name: "Dependency Review"
uses: actions/dependency-review-action@v3

terraform-plan-and-apply-dev:
environment: Development
runs-on: ubuntu-latest

concurrency:
group: ${{ github.repository }}-dev

steps:
- uses: actions/checkout@v4

- uses: frasermolyneux/actions/terraform-plan-and-apply@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/dev.tfvars"
terraform-backend-file: "backends/dev.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

terraform-plan-prd:
if: github.actor != 'dependabot[bot]' # dependabot context has no permissions to prod so skip this check
environment: Production
runs-on: ubuntu-latest

concurrency:
group: ${{ github.repository }}-prd

steps:
- uses: actions/checkout@v4

- uses: frasermolyneux/actions/terraform-plan@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/prd.tfvars"
terraform-backend-file: "backends/prd.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
55 changes: 55 additions & 0 deletions .github/workflows/release-to-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Release to Production

on:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: "0 3 * * 4" # Every Thursday at 3am

permissions:
id-token: write # This is required for Az CLI Login
contents: read # This is required for actions/checkout

concurrency:
group: ${{ github.workflow }}

jobs:
terraform-plan-and-apply-dev:
environment: Development
runs-on: ubuntu-latest

concurrency:
group: ${{ github.repository }}-dev

steps:
- uses: actions/checkout@v4

- uses: frasermolyneux/actions/terraform-plan-and-apply@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/dev.tfvars"
terraform-backend-file: "backends/dev.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

terraform-plan-and-apply-prd:
environment: Production
runs-on: ubuntu-latest

concurrency:
group: ${{ github.repository }}-prd

steps:
- uses: actions/checkout@v4

- uses: frasermolyneux/actions/terraform-plan-and-apply@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/prd.tfvars"
terraform-backend-file: "backends/prd.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
8 changes: 8 additions & 0 deletions terraform/app_insights.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "azurerm_application_insights" "ai" {
name = local.app_insights_name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
workspace_id = "/subscriptions/${var.log_analytics_subscription_id}/resourceGroups/${var.log_analytics_resource_group_name}/providers/Microsoft.OperationalInsights/workspaces/${var.log_analytics_workspace_name}"

application_type = "web"
}
6 changes: 6 additions & 0 deletions terraform/backends/dev-azuread.backend.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
storage_account_name = "saf39fd6adf871"
container_name = "tfstate"
key = "terraform.tfstate"
use_azuread_auth = true
subscription_id = "7760848c-794d-4a19-8cb2-52f71a21ac2b"
tenant_id = "e56a6947-bb9a-4a6e-846a-1f118d1c3a14"
7 changes: 7 additions & 0 deletions terraform/backends/dev.backend.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource_group_name = "rg-tf-portal-core-dev-uksouth-01"
storage_account_name = "saf39fd6adf871"
container_name = "tfstate"
key = "terraform.tfstate"
use_oidc = true
subscription_id = "7760848c-794d-4a19-8cb2-52f71a21ac2b"
tenant_id = "e56a6947-bb9a-4a6e-846a-1f118d1c3a14"
7 changes: 7 additions & 0 deletions terraform/backends/prd.backend.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource_group_name = "rg-tf-portal-core-prd-uksouth-01"
storage_account_name = "sa2e3e95eb7965"
container_name = "tfstate"
key = "terraform.tfstate"
use_oidc = true
subscription_id = "7760848c-794d-4a19-8cb2-52f71a21ac2b"
tenant_id = "e56a6947-bb9a-4a6e-846a-1f118d1c3a14"
6 changes: 6 additions & 0 deletions terraform/common.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "azurerm_resource_group" "rg" {
name = local.resource_group_name
location = var.location

tags = var.tags
}
4 changes: 4 additions & 0 deletions terraform/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
locals {
resource_group_name = "rg-portal-core-${var.environment}-${var.location}-${var.instance}"
app_insights_name = "ai-portal-core-${var.environment}-${var.location}-${var.instance}"
}
35 changes: 35 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
terraform {
required_version = ">= 1.6.2"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.84.0"
}
}

backend "azurerm" {}
}

provider "azurerm" {
subscription_id = var.subscription_id

features {
resource_group {
# Resource group is only used by workload, App Insights creates artifacts that need to be deleted
prevent_deletion_if_contains_resources = false
}
}
}

data "azurerm_client_config" "current" {}

data "azuread_client_config" "current" {}

resource "random_id" "environment_id" {
byte_length = 6
}

resource "time_rotating" "thirty_days" {
rotation_days = 30
}
1 change: 1 addition & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

16 changes: 16 additions & 0 deletions terraform/tfvars/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
environment = "dev"
location = "uksouth"
instance = "01"

subscription_id = "d68448b0-9947-46d7-8771-baa331a3063a"

log_analytics_subscription_id = "d68448b0-9947-46d7-8771-baa331a3063a"
log_analytics_resource_group_name = "rg-platform-logging-prd-uksouth-01"
log_analytics_workspace_name = "log-platform-prd-uksouth-01"

tags = {
Environment = "dev",
Workload = "portal",
DeployedBy = "GitHub-Terraform",
Git = "https://github.com/frasermolyneux/portal-core"
}
16 changes: 16 additions & 0 deletions terraform/tfvars/prd.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
environment = "prd"
location = "uksouth"
instance = "01"

subscription_id = "32444f38-32f4-409f-889c-8e8aa2b5b4d1"

log_analytics_subscription_id = "d68448b0-9947-46d7-8771-baa331a3063a"
log_analytics_resource_group_name = "rg-platform-logging-prd-uksouth-01"
log_analytics_workspace_name = "log-platform-prd-uksouth-01"

tags = {
Environment = "prd",
Workload = "portal",
DeployedBy = "GitHub-Terraform",
Git = "https://github.com/frasermolyneux/portal-core"
}
21 changes: 21 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "environment" {
default = "dev"
}

variable "location" {
default = "uksouth"
}

variable "instance" {
default = "01"
}

variable "subscription_id" {}

variable "log_analytics_subscription_id" {}
variable "log_analytics_resource_group_name" {}
variable "log_analytics_workspace_name" {}

variable "tags" {
default = {}
}

0 comments on commit d95cb79

Please sign in to comment.