Skip to content

Instantly share code, notes, and snippets.

@yogesh174
Created June 6, 2021 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yogesh174/2d2c967d4be30a11c82a2069ca7cba6c to your computer and use it in GitHub Desktop.
Save yogesh174/2d2c967d4be30a11c82a2069ca7cba6c to your computer and use it in GitHub Desktop.
Multi-cloud K8s cluster with Terraform and Ansible
#######################################
######## Create resource group ########
#######################################
resource "azurerm_resource_group" "k8s" {
name = var.azure_rg_name
location = var.azure_rg_location
}
########################################
######## Create virtual network ########
########################################
resource "azurerm_virtual_network" "k8s" {
name = var.azure_vn_name
address_space = var.azure_vn_adress_space
location = azurerm_resource_group.k8s.location
resource_group_name = azurerm_resource_group.k8s.name
}
###############################
######## Create subnet ########
###############################
resource "azurerm_subnet" "k8s" {
name = var.azure_subnet_name
resource_group_name = azurerm_resource_group.k8s.name
virtual_network_name = azurerm_virtual_network.k8s.name
address_prefixes = var.azure_subnet_adress_prefixes
}
##################################
######## Create public ip ########
##################################
resource "azurerm_public_ip" "k8s_public_ip" {
count = var.azure_nodes
name = "k8s-${count.index}"
location = azurerm_resource_group.k8s.location
resource_group_name = azurerm_resource_group.k8s.name
allocation_method = "Static"
sku = "Basic"
}
##########################################
######## Create network interface ########
##########################################
resource "azurerm_network_interface" "k8s" {
count = var.azure_nodes
name = "k8s-nic-${count.index}"
location = azurerm_resource_group.k8s.location
resource_group_name = azurerm_resource_group.k8s.name
ip_configuration {
name = "k8s"
subnet_id = azurerm_subnet.k8s.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.k8s_public_ip[count.index].id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment