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

Refactoring #91

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 89 additions & 8 deletions .github/workflows/terraform-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,71 @@ on:

env:
TF_WORKSPACE: gha
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}

jobs:
terraform:
name: 'Terraform Validate and plan'
test_storagerg_module:
name: 'Test and deploy 01_Storage_rg module with Terraform Validate and plan'
Copy link
Member

@msrn msrn Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workflow now tests and deploys the storagerg module to Azure. Deployhono -module plan would fail because that module needs outputs of storagerg -module shares. Because of this storage_rg needs to be deployed.

runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'safe-to-test')

env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}

# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: ./01_storage_rg
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

# Install the latest version of Terraform CLI. Enable wrapper for output
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: true

# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
id: init
run: terraform init

# Validate config files
- name: Terraform Validate
id: validate
run: terraform validate -no-color

# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
id: fmt
run: terraform fmt -recursive -check -list=true
#continue-on-error: true

# Generates an execution plan for Terraform
- name: Terraform Plan
id: plan
run: terraform plan
#continue-on-error: true
- name: Terraform Apply
id: apply
run: terraform apply -auto-approve

test_deployhono_module:
name: 'Test 02_deploy_hono module with Terraform Validate and plan'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test deployHono module with validate and plan.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this workflow here
msrn#5
You can see output of checks here
https://github.com/msrn/smad-deploy-azure/actions/runs/1663019863

needs: test_storagerg_module
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'safe-to-test')

# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: ./02_deployHono
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
Expand Down Expand Up @@ -61,6 +108,40 @@ jobs:
id: plan
run: terraform plan
#continue-on-error: true

destroy_storagerg_module:
name: 'Destroy 01_Storage_rg module from Azure subscription'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destroy previously made storagerg

needs: test_deployhono_module
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'safe-to-test')

# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: ./01_storage_rg
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

# Install the latest version of Terraform CLI. Enable wrapper for output
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: true

# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
id: init
run: terraform init

- name: Terraform Destroy
id: destroy
run: terraform destroy -auto-approve


# TODO
# Make a better output
Expand Down
98 changes: 0 additions & 98 deletions .terraform.lock.hcl

This file was deleted.

21 changes: 21 additions & 0 deletions 00_tfstate_storage/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.45.1"
version = "~> 2.68.0"
}
}
}
Expand All @@ -11,15 +11,6 @@ provider "azurerm" {
features {}
}

# NOTE: Needed when storage account uniqueness wants to be automatically achieved
# resource "random_string" "storage_account_name_suffix" {
# length = 8
# upper = false
# number = true
# lower = true
# special = false
# }

resource "azurerm_resource_group" "tfstate_rg" {
name = "${lower(var.project_name)}-${var.tfstate_resource_group_name_suffix}"
location = var.location
Expand All @@ -32,12 +23,6 @@ resource "azurerm_resource_group" "tfstate_rg" {
}

resource "azurerm_storage_account" "tfstate_sa" {
depends_on = [azurerm_resource_group.tfstate_rg]

# 'name' must be unique across the entire Azure service, not just within the resource group.
# 'name' can only consist of lowercase letters and numbers, and must be between 3 and 24 characters long
# NOTE: Uncomment the next line to generate suffix for storage account.
# name = "${lower(var.project_name)}tfstatesa${random_id.storage_account_name_suffix.result}"
name = "${lower(var.project_name)}${var.tfstate_storage_account_name_suffix}"
resource_group_name = azurerm_resource_group.tfstate_rg.name
location = var.location
Expand All @@ -53,7 +38,6 @@ resource "azurerm_storage_account" "tfstate_sa" {
}

resource "azurerm_storage_container" "tfstate_container" {
depends_on = [azurerm_storage_account.tfstate_sa]
name = var.tfstate_container_name
storage_account_name = azurerm_storage_account.tfstate_sa.name
container_access_type = "private"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
variable "environment" {
type = string
default = "development"
}

variable "location" {
type = string
default = "West Europe"
}

variable "project_name" {
default = "kuksatrng"
type = string
default = "smaddis"
}

variable "tfstate_resource_group_name_suffix" {
type = string
default = "tfstate-rg"
}

# 'name' must be unique across the entire Azure service,
# 'name' must be unique across the entire Azure service,
# not just within the resource group.
# 'name' can only consist of lowercase letters and numbers,
# 'name' can only consist of lowercase letters and numbers,
# and must be between 3 and 24 characters long.
variable "tfstate_storage_account_name_suffix" {
type = string
default = "tfstatesa"
}

variable "tfstate_container_name" {
type = string
default = "tfstate"
}

39 changes: 39 additions & 0 deletions 01_storage_rg/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading