adding terraform scripts
+245 −1 · 8 files changed
-
terraform/README.md+4 −1 -
terraform/main.tf+22 −0 -
terraform/modules/terraforn-azurerm-aks/main.tf+36 −0 -
terraform/modules/vm/vm.tf+76 −0 -
terraform/outputs.tf+9 −0 -
terraform/terraform.tfvars+9 −0 -
terraform/variables.tf+81 −0 -
terraform/versions.tf+8 −0
@@ -40,4 +40,7 @@ File and Directory Roles **README.md:** Provides documentation for your project, explaining its purpose, how to use it, and any prerequisites or configuration steps. -**Modules Directory:** Contains subdirectories for each modularized component of your infrastructure, like networking or compute resources. This allows you to encapsulate and reuse configurations. \ No newline at end of file +**Modules Directory:** Contains subdirectories for each modularized component of your infrastructure, like networking or compute resources. This allows you to encapsulate and reuse configurations. + + +Define variables @@ -0,0 +1,22 @@ +provider "azurerm" { + features {} +} + +module "aks" { + source = "./modules/terraform-azurerm-aks" + resource_group_name = var.resource_group_name + kubernetes_cluster_name = var.cluster_name + kubernetes_version = var.kubernetes_version + agents_count = var.node_count + agents_max_count = var.agents_max_count + agents_min_count = var.agents_min_count + agents_size = var.vm_size + client_id = var.client_id + client_secret = var.client_secret + # Add any other required variables from the module +} + +module "vm" { + source = "./modules/vm" + # Add the required variables for the VM module +} @@ -0,0 +1,36 @@ +provider "azurerm" { + features {} + version = "~> 2.0" +} + +module "aks" { + source = "github.com/Azure/terraform-azurerm-aks?ref=main" + version = "1.0.0" # Use the appropriate version + + resource_group_name = var.resource_group_name + location = var.location + cluster_name = var.cluster_name + kubernetes_version = var.kubernetes_version + dns_prefix = var.dns_prefix + + default_node_pool { + name = var.default_node_pool_name + node_count = var.node_count + vm_size = var.vm_size + } + + linux_profile { + admin_username = var.admin_username + ssh_key { + key_data = file(var.ssh_public_key) + } + } + + service_principal { + client_id = var.client_id + client_secret = var.client_secret + } + + tags = var.tags +} + @@ -0,0 +1,76 @@ +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "East US" +} + +resource "azurerm_virtual_network" "example" { + name = "example-network" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_subnet" "example" { + name = "example-subnet" + resource_group_name = azurerm_resource_group.example.name + virtual_network_name = azurerm_virtual_network.example.name + address_prefixes = ["10.0.2.0/24"] +} + +resource "azurerm_public_ip" "example" { + name = "example-publicip" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + allocation_method = "Dynamic" +} + +resource "azurerm_network_security_group" "example" { + name = "example-nsg" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_network_interface" "example" { + name = "example-nic" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + + ip_configuration { + name = "internal" + subnet_id = azurerm_subnet.example.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.example.id + } +} + +resource "azurerm_linux_virtual_machine" "example" { + name = "example-vm" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + size = "Standard_F2" + admin_username = "adminuser" + network_interface_ids = [ + azurerm_network_interface.example.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "18.04-LTS" + version = "latest" + } + + admin_ssh_key { + username = "adminuser" + public_key = file("~/.ssh/id_rsa.pub") + } +} @@ -0,0 +1,9 @@ +output "aks_cluster_name" { + description = "The name of the AKS cluster" + value = module.aks.aks_name +} + +output "aks_cluster_id" { + description = "The ID of the AKS cluster" + value = module.aks.aks_id +} @@ -0,0 +1,9 @@ +resource_group_name = "your-resource-group-name" +cluster_name = "your-aks-cluster-name" +kubernetes_version = "1.24.6" +node_count = 3 +agents_max_count = 5 +agents_min_count = 1 +vm_size = "Standard_D2s_v3" +client_id = "your-service-principal-client-id" +client_secret = "your-service-principal-client-secret"x @@ -0,0 +1,81 @@ +variable "azure_region" { + description = "azure region" + type = string + default = "eu-west-2" +} + +variable "name" { + description = "name" + type = string + default = "app-failover-and-traffic" +} + +variable "project" { + description = "The name of the project" + type = string + default = "automation-project-one" +} + +variable "client" { + description = "The client for the project" + type = string + default = "public" +} + +variable "owner" { + description = "The owner of the project" + type = string + default = "Custom Text" +} + +variable "environment" { + description = "The project environment" + type = string + default = "dev" +} + +variable "resource_group_name" { + description = "The name of the resource group" + type = string +} + +variable "cluster_name" { + description = "The name of the AKS cluster" + type = string +} + +variable "kubernetes_version" { + description = "The Kubernetes version for the AKS cluster" + type = string +} + +variable "node_count" { + description = "The number of nodes in the default node pool" + type = number +} + +variable "agents_max_count" { + description = "The maximum number of nodes in the default node pool" + type = number +} + +variable "agents_min_count" { + description = "The minimum number of nodes in the default node pool" + type = number +} + +variable "vm_size" { + description = "The size of the virtual machines in the default node pool" + type = string +} + +variable "client_id" { + description = "The client ID of the service principal" + type = string +} + +variable "client_secret" { + description = "The client secret of the service principal" + type = string +} + @@ -0,0 +1,8 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.0" + } + } +}