Skip to content

Commit a8d1bf3

Browse files
committed
starting point
0 parents  commit a8d1bf3

12 files changed

+129
-0
lines changed

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
# .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
8+
# Crash log files
9+
crash.log
10+
11+
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
12+
# .tfvars files are managed as part of configuration and so should be included in
13+
# version control.
14+
#
15+
# example.tfvars
16+
17+
# Ignore override files as they are usually used to override resources locally and so
18+
# are not checked in
19+
override.tf
20+
override.tf.json
21+
*_override.tf
22+
*_override.tf.json
23+
24+
# Include override files you do wish to add to version control using negated pattern
25+
#
26+
# !example_override.tf
27+
28+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
29+
# example: *tfplan*
30+
envs/*.tfplan
31+
32+
.terraform.lock.hcl
33+
34+
resources/*
35+
36+
scripts/set-local-envs.ps1

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Gordon Beeming Demos
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Building basic Azure infrastructure using Terraform

envs/shared.tfbackend

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource_group_name = "demo4-shared-rg"
2+
storage_account_name = "demo4dso"
3+
container_name = "tfstate"
4+
key = "shared.tfstate"

envs/shared.tfvars

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
deploy_region = "westeurope"
2+
resource_group_name = "demo4-shared-rg"
3+
environment_name = "demo"

main.tf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_version = "= 1.2.4"
3+
4+
backend "azurerm" {}
5+
}
6+
7+
# Configure the Microsoft Azure Provider
8+
provider "azurerm" {
9+
features {}
10+
}
11+
12+
data "azurerm_client_config" "current" {}
13+
14+
output "tenant_id" {
15+
value = data.azurerm_client_config.current.tenant_id
16+
}
17+
18+
output "subscription_id" {
19+
value = data.azurerm_client_config.current.subscription_id
20+
}

resource-groups.tf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
resource "azurerm_resource_group" "demo" {
3+
name = var.resource_group_name
4+
location = var.deploy_region
5+
6+
lifecycle {
7+
prevent_destroy = true
8+
}
9+
}
10+
11+
output "demo_resource_group" {
12+
value = azurerm_resource_group.demo.name
13+
}

scripts/apply.bat

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cd ..
2+
terraform apply -auto-approve %* "envs/shared.tfplan"
3+
cd scripts

scripts/create-backend.ps1

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$SharedResourceGroup = "demo4-shared-rg"
2+
$DeployRegion = "westeurope"
3+
$SharedStorage = "demo4dso"
4+
$SharedStorageContainer = "tfstate"
5+
6+
az group create --resource-group $SharedResourceGroup --location $DeployRegion
7+
8+
az storage account create --name $SharedStorage --resource-group $SharedResourceGroup --location $DeployRegion --access-tier Hot --allow-blob-public-access false --https-only true --kind StorageV2 --sku Standard_ZRS
9+
10+
az storage container create -n $SharedStorageContainer --account-name $SharedStorage --resource-group $SharedResourceGroup

scripts/init.bat

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cd ..
2+
terraform init -var-file="envs/shared.tfvars" -backend-config="envs/shared.tfbackend" %*
3+
cd scripts

scripts/plan.bat

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cd ..
2+
terraform plan -input=false -var-file="envs/shared.tfvars" -out="envs/shared.tfplan" %*
3+
cd scripts

variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
variable "deploy_region" {
2+
type = string
3+
default = "westeurope"
4+
}
5+
6+
variable "resource_group_name" {
7+
type = string
8+
}
9+
10+
variable "environment_name" {
11+
type = string
12+
}

0 commit comments

Comments
 (0)