From 19932df1540cb0e69c6d626a6733479b13d803a5 Mon Sep 17 00:00:00 2001 From: Pamir Date: Sun, 12 Apr 2020 12:42:22 +0300 Subject: [PATCH 1/4] foreach folder fixed --- 04-variables/{foreach => 04-foreach}/providers.tf | 0 04-variables/{foreach => 04-foreach}/resources.tf | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename 04-variables/{foreach => 04-foreach}/providers.tf (100%) rename 04-variables/{foreach => 04-foreach}/resources.tf (100%) diff --git a/04-variables/foreach/providers.tf b/04-variables/04-foreach/providers.tf similarity index 100% rename from 04-variables/foreach/providers.tf rename to 04-variables/04-foreach/providers.tf diff --git a/04-variables/foreach/resources.tf b/04-variables/04-foreach/resources.tf similarity index 100% rename from 04-variables/foreach/resources.tf rename to 04-variables/04-foreach/resources.tf From ae67170058ed301e2a745e35674565be584043e0 Mon Sep 17 00:00:00 2001 From: Pamir Date: Sun, 12 Apr 2020 13:49:49 +0300 Subject: [PATCH 2/4] operators and loops added --- 04-variables/05-operators/main.tf | 28 ++++++++++++++++++++++++++ 04-variables/05-operators/providers.tf | 3 +++ 04-variables/06-loops/main.tf | 22 ++++++++++++++++++++ 04-variables/06-loops/providers.tf | 4 ++++ 4 files changed, 57 insertions(+) create mode 100644 04-variables/05-operators/main.tf create mode 100644 04-variables/05-operators/providers.tf create mode 100644 04-variables/06-loops/main.tf create mode 100644 04-variables/06-loops/providers.tf diff --git a/04-variables/05-operators/main.tf b/04-variables/05-operators/main.tf new file mode 100644 index 0000000..7c3d903 --- /dev/null +++ b/04-variables/05-operators/main.tf @@ -0,0 +1,28 @@ +/* +variable "customer" { + type = map(object({ + name = string + id = number, + is_active = bool, + })) +} +*/ + + +locals { + three = 1 + 2 + logical = 2 < 3 + time = timestamp() +} + +output "sum_result" { + value = local.three +} + +output "logical_result" { + value = local.logical +} + +output "apply_date" { + value = formatdate("YYYYMMDD",local.time) +} \ No newline at end of file diff --git a/04-variables/05-operators/providers.tf b/04-variables/05-operators/providers.tf new file mode 100644 index 0000000..a68cab5 --- /dev/null +++ b/04-variables/05-operators/providers.tf @@ -0,0 +1,3 @@ +provider "random" { + version = "=2.2.1" +} \ No newline at end of file diff --git a/04-variables/06-loops/main.tf b/04-variables/06-loops/main.tf new file mode 100644 index 0000000..ea97ee6 --- /dev/null +++ b/04-variables/06-loops/main.tf @@ -0,0 +1,22 @@ +variable "locations" { + type = list + default = [ + "westeurope", + "westus", + "eastus", + "easteurope" + ] +} + +locals { + numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] + evens = [for i in local.numbers : (i + 10) if i % 2 == 0] + +} +output "upper_locations" { + value = [for l in var.locations : upper(l)] +} + +output "even_numbers" { + value = local.evens +} \ No newline at end of file diff --git a/04-variables/06-loops/providers.tf b/04-variables/06-loops/providers.tf new file mode 100644 index 0000000..497a6bc --- /dev/null +++ b/04-variables/06-loops/providers.tf @@ -0,0 +1,4 @@ +provider "random" { + version = "=2.2.1" +} + From bbeb9e7d9623d9df83427089ce8c16ccf7131eef Mon Sep 17 00:00:00 2001 From: Pamir Date: Sun, 12 Apr 2020 14:38:59 +0300 Subject: [PATCH 3/4] folder structure added --- .DS_Store | Bin 6148 -> 6148 bytes 08-modules/01-module-usage/Readme.md | 0 08-modules/02-custom-modules/Readme.md | 0 08-modules/03-publihing-module/Readme.md | 0 09-workspace/Readme.md | 0 10-backends/Readme.md | 0 11-keyvaul-integration/Readme.md | 0 12-opa-integration/Readme.md | 0 .../01-module-structure/Readme.md | 0 .../02-jenkins-integration/Readme.md | 0 .../03-azure-devops-integration/Readme.md | 0 13-infra-best-practices/Readme.md | 0 12 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 08-modules/01-module-usage/Readme.md create mode 100644 08-modules/02-custom-modules/Readme.md create mode 100644 08-modules/03-publihing-module/Readme.md create mode 100644 09-workspace/Readme.md create mode 100644 10-backends/Readme.md create mode 100644 11-keyvaul-integration/Readme.md create mode 100644 12-opa-integration/Readme.md create mode 100644 13-infra-best-practices/01-module-structure/Readme.md create mode 100644 13-infra-best-practices/02-jenkins-integration/Readme.md create mode 100644 13-infra-best-practices/03-azure-devops-integration/Readme.md create mode 100644 13-infra-best-practices/Readme.md diff --git a/.DS_Store b/.DS_Store index f9ae37689d7b8652c1cd4f1ed1701310f8e50770..e1d3e79ca1fce056f50a9526e791448ef96ffa05 100644 GIT binary patch delta 338 zcmZoMXfc=|#>B)qu~2NHo+2aD!~pA!7aABR8;Gz>?3b)hDlaZb%E?b+U|{&1RFIQd zTw-8wgOQ1ug_Vt+gOiJ!lbes5Gd4IQzdX1kv81%vDX}PCKqfddB{eCrC_FQzBqJm> z&ow8tEH%%+$S1KRwI~{-I3zzm2dDtTPD~2ROf8QW5OL1WD@n}EODzJM2Qs5Ru_z`y zGcP5-+$p~_FQpi)0ctv!9gtX(0W^q1*&*ox(2WcXoE)6-0%FzG2098RCWf^-3f1Q3 zAhxktZ7nAUhorh&P+VzK->lh7mM&X<;2>BJ10y4ZW)OtZFpBZe#-0Z(o7p+|Ie=lb e@!)sn$^0U^A|PpymIeq7*1b7IWCQcW1{MGWyCJzu~2NHo+2aT!~knX#>qTPGMk;5kFab`V4lsinVo~51E^$kAoF+T a$^0U^oQw<%3 Date: Sun, 12 Apr 2020 16:06:46 +0300 Subject: [PATCH 4/4] modules sample added --- 08-modules/01-module-usage/main.tf | 55 +++++++++++++++++++++ 08-modules/01-module-usage/providers.tf | 9 ++++ 08-modules/01-module-usage/terraform.tfvars | 3 ++ 08-modules/01-module-usage/variables.tf | 6 +++ 4 files changed, 73 insertions(+) create mode 100644 08-modules/01-module-usage/main.tf create mode 100644 08-modules/01-module-usage/providers.tf create mode 100644 08-modules/01-module-usage/terraform.tfvars create mode 100644 08-modules/01-module-usage/variables.tf diff --git a/08-modules/01-module-usage/main.tf b/08-modules/01-module-usage/main.tf new file mode 100644 index 0000000..45a4a13 --- /dev/null +++ b/08-modules/01-module-usage/main.tf @@ -0,0 +1,55 @@ +/* +terraform apply \ + -var-file='secret.tfvars' \ + -var-file='production.tfvars' +*/ + +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +module "linuxservers" { + source = "Azure/compute/azurerm" + resource_group_name = azurerm_resource_group.example.name + vm_os_simple = "UbuntuServer" + public_ip_dns = ["linsimplevmips"] // change to a unique name per datacenter region + vnet_subnet_id = module.network.vnet_subnets[0] +} + +module "windowsservers" { + source = "Azure/compute/azurerm" + resource_group_name = azurerm_resource_group.example.name + is_windows_image = true + vm_hostname = "mywinvm" // line can be removed if only one VM module per resource group + admin_password = "ComplxP@ssw0rd!" + vm_os_simple = "WindowsServer" + public_ip_dns = ["winsimplevmips"] // change to a unique name per datacenter region + vnet_subnet_id = module.network.vnet_subnets[1] +} + +module "network" { + source = "Azure/network/azurerm" + version = "3.0.0" + resource_group_name = azurerm_resource_group.example.name + subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"] + subnet_names = ["subnet1", "subnet2"] +} + +#todo: version will be added +#Search for warnings in tf apply +module "aks" { + source = "Azure/aks/azurerm" + resource_group_name = azurerm_resource_group.example.name + client_id = var.client_id + client_secret = var.client_secret + prefix = "az" +} + +output "linux_vm_public_name" { + value = module.linuxservers.public_ip_dns_name +} + +output "windows_vm_public_name" { + value = module.windowsservers.public_ip_dns_name +} \ No newline at end of file diff --git a/08-modules/01-module-usage/providers.tf b/08-modules/01-module-usage/providers.tf new file mode 100644 index 0000000..ff73c30 --- /dev/null +++ b/08-modules/01-module-usage/providers.tf @@ -0,0 +1,9 @@ +#export TF_CLI_CONFIG_FILE=$PWD/terraform.rc +#export TF_LOG=TRACE +#export TF_LOG_PATH=./terraform.log + +provider "azurerm" { + # whilst the `version` attribute is optional, we recommend pinning to a given version of the Provider + version = "=2.0.0" + features {} +} diff --git a/08-modules/01-module-usage/terraform.tfvars b/08-modules/01-module-usage/terraform.tfvars new file mode 100644 index 0000000..78a198c --- /dev/null +++ b/08-modules/01-module-usage/terraform.tfvars @@ -0,0 +1,3 @@ +#az ad sp create-for-rbac -n "terraform-aks" +client_id = "xxxx" +client_secret = "xxxx" \ No newline at end of file diff --git a/08-modules/01-module-usage/variables.tf b/08-modules/01-module-usage/variables.tf new file mode 100644 index 0000000..b75d12b --- /dev/null +++ b/08-modules/01-module-usage/variables.tf @@ -0,0 +1,6 @@ +variable "client_id" { + type = string +} +variable "client_secret" { + type = string +} \ No newline at end of file