diff --git a/.DS_Store b/.DS_Store index f9ae376..e1d3e79 100644 Binary files a/.DS_Store and b/.DS_Store differ 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 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" +} + diff --git a/08-modules/01-module-usage/Readme.md b/08-modules/01-module-usage/Readme.md new file mode 100644 index 0000000..e69de29 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 diff --git a/08-modules/02-custom-modules/Readme.md b/08-modules/02-custom-modules/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/08-modules/03-publihing-module/Readme.md b/08-modules/03-publihing-module/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/09-workspace/Readme.md b/09-workspace/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/10-backends/Readme.md b/10-backends/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/11-keyvaul-integration/Readme.md b/11-keyvaul-integration/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/12-opa-integration/Readme.md b/12-opa-integration/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/13-infra-best-practices/01-module-structure/Readme.md b/13-infra-best-practices/01-module-structure/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/13-infra-best-practices/02-jenkins-integration/Readme.md b/13-infra-best-practices/02-jenkins-integration/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/13-infra-best-practices/03-azure-devops-integration/Readme.md b/13-infra-best-practices/03-azure-devops-integration/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/13-infra-best-practices/Readme.md b/13-infra-best-practices/Readme.md new file mode 100644 index 0000000..e69de29