Skip to content

Commit

Permalink
ci added | gitignore update | test configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kolosovpetro committed Aug 30, 2023
1 parent dff080f commit cc8ccf0
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 2 deletions.
File renamed without changes.
66 changes: 66 additions & 0 deletions .github/workflows/terraform-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Validate Terraform

on:
push:
branches:
- master
- main
- develop

pull_request:
branches:
- master
- main
- develop

workflow_dispatch:

# schedule:
# - cron: '0 0 * * 0'

jobs:
build-webapp:
name: Validate Terraform
runs-on: ${{ matrix.environment }}
strategy:
matrix:
environment:
- ubuntu-latest

env:
DOTNET_NOLOGO: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
ACTIONS_RUNNER_DEBUG: true
TF_LOG: INFO
ARM_CLIENT_ID: ""
ARM_CLIENT_SECRET: ${{ secrets.TF_ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ""
ARM_TENANT_ID: ""
WORKING_DIR: "./"

steps:
- name: Fetch Sources
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: latest

- name: Terraform Version
run: terraform -v
working-directory: ${{ env.WORKING_DIR }}

- name: Terraform Init
run: terraform init -backend=false
working-directory: ${{ env.WORKING_DIR }}

- name: Terraform Validate
run: terraform validate
working-directory: ${{ env.WORKING_DIR }}

- name: Terraform Format
run: terraform fmt -check
working-directory: ${{ env.WORKING_DIR }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea
.ssh
*.conf
.terraform
*.tfplan
*.tfstate
*.lock.info
*.tfstate.backup
21 changes: 21 additions & 0 deletions .terraform.lock.hcl

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

File renamed without changes.
52 changes: 52 additions & 0 deletions azure-pipelines/azdo-terraform-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
trigger:
batch: true
branches:
include:
- master
paths:
include:
- '*'

pr:
branches:
include:
- '*'

variables:
- name: TF_LOG
value: INFO
- name: WORKING_DIR
value: '$(System.DefaultWorkingDirectory)'

stages:
- stage: "Terraform_CI"
displayName: "Terraform Validate"
jobs:
- job: Terraform_CI
displayName: "Terraform Validate"
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
fetchDepth: 0

- task: TerraformInstaller@0
displayName: 'Terraform Installer'
inputs:
terraformVersion: 'latest'

- script: terraform -v
displayName: 'Terraform Version'
workingDirectory: '$(WORKING_DIR)'

- script: terraform init -backend=false
displayName: 'Terraform Init'
workingDirectory: '$(WORKING_DIR)'

- script: terraform validate
displayName: 'Terraform Validate'
workingDirectory: '$(WORKING_DIR)'

- script: terraform fmt -check
displayName: 'Terraform Format'
workingDirectory: '$(WORKING_DIR)'
3 changes: 3 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
rg_name = "${var.resource_group_name}-${var.prefix}"
}
12 changes: 12 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
data "azurerm_client_config" "current" {}

resource "azurerm_resource_group" "public" {
location = var.resource_group_location
name = local.rg_name
}

module "resource_group" {
source = "./modules/example_submodule"
resource_group_location = "northeurope"
resource_group_name = "rg-from-module"
}
8 changes: 8 additions & 0 deletions modules/example_submodule/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
locals {
rg_name = var.resource_group_name
}

resource "azurerm_resource_group" "public" {
location = var.resource_group_location
name = local.rg_name
}
3 changes: 3 additions & 0 deletions modules/example_submodule/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "rg_id" {
value = azurerm_resource_group.public.id
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
variable "resourece_group_name" {
variable "resource_group_name" {
type = string
description = "Resource group name"
}

variable "resourece_group_location" {
variable "resource_group_location" {
type = string
description = "Resource group location"
}
Empty file removed modules/main.tf
Empty file.
File renamed without changes.
7 changes: 7 additions & 0 deletions provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
5 changes: 5 additions & 0 deletions terraform.auto.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"resource_group_name": "rg-terraform-template",
"resource_group_location": "northeurope",
"prefix": "tf01"
}
14 changes: 14 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "resource_group_name" {
type = string
description = "Resource group name"
}

variable "resource_group_location" {
type = string
description = "Resource group location"
}

variable "prefix" {
type = string
description = "Prefix for all resources"
}
File renamed without changes.

0 comments on commit cc8ccf0

Please sign in to comment.