├── 1-as-diagram
├── README.md
└── vm.png
├── 2-as-script
├── README.md
└── freebsd-create-vm.sh
├── 3-as-code
├── README.md
├── k8s.json
├── k8s.tfvars
├── main.tf
└── variables.tf
├── 4-as-software
└── README.md
└── README.md
/1-as-diagram/README.md:
--------------------------------------------------------------------------------
1 | # Infrastructure as a diagram
2 |
3 | ### Virtual Machine
4 |
5 | Here we have a simple diagram of infrastructure.
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/1-as-diagram/vm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krisnova/cloud-native-infrastructure-demo/57a9d6fc87e6aa3fc12d41c47eeb32720587f109/1-as-diagram/vm.png
--------------------------------------------------------------------------------
/2-as-script/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krisnova/cloud-native-infrastructure-demo/57a9d6fc87e6aa3fc12d41c47eeb32720587f109/2-as-script/README.md
--------------------------------------------------------------------------------
/2-as-script/freebsd-create-vm.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | pkg install -y bash nano
3 | curl -L https://aka.ms/InstallAzureCli | bash
4 | az login
5 | az group delete -n infra-2 --yes
6 | az group create --name infra-2 --location eastus
7 | az vm create --resource-group infra-2 --name infra-2 --image UbuntuLTS --ssh-key-value "ssh-rsa
8 | AAAAB3NzaC1yc2EAAAADAQABAAABAQC34QGJe1+MkcimmQmiRgZiZX5y7k/z7Y4W2H0WTnh/WhKkUvjRgWcd3A0kUb5MIW9zbRzBFIJBEBrm8HRlF4enXRACr+tVbHUqI5JO3xIEHKWkJHGf0Bg43+VW8X/7ftP7QPe5imet5TL+AqsC62Wq2aUTZMHag1R6xv4AGHHPNx/dbbRn26Mtrc8Jh4WJXtYfk3CDU46zHHUW+VInuDMFmtW4ykeyPqBaKQvrjr+XQm15vfsrtoaBG4JweKOD/LJLs+tiKtsVMf55sWZxdPdHLtO1/Rsb+Z+1wSeT8mM1tBanigShxmJeC0gZ8HQOO2OveF0jYUjMK4wPwGryPZkf" --admin-username kris
9 |
--------------------------------------------------------------------------------
/3-as-code/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krisnova/cloud-native-infrastructure-demo/57a9d6fc87e6aa3fc12d41c47eeb32720587f109/3-as-code/README.md
--------------------------------------------------------------------------------
/3-as-code/k8s.json:
--------------------------------------------------------------------------------
1 | {
2 | "apiVersion": "vlabs",
3 | "properties": {
4 | "orchestratorProfile": {
5 | "orchestratorType": "Kubernetes"
6 | },
7 | "masterProfile": {
8 | "count": ${master_vm_count},
9 | "dnsPrefix": "${dns_prefix}",
10 | "vmSize": "${vm_size}",
11 | "vnetSubnetId": "${subnet_id}",
12 | "firstConsecutiveStaticIP": "${first_master_ip}"
13 | },
14 | "agentPoolProfiles": [
15 | {
16 | "name": "agentpool1",
17 | "count": ${worker_vm_count},
18 | "vmSize": "${vm_size}",
19 | "vnetSubnetId": "${subnet_id}",
20 | "availabilityProfile": "AvailabilitySet"
21 | }
22 | ],
23 | "linuxProfile": {
24 | "adminUsername": "${admin_user}",
25 | "ssh": {
26 | "publicKeys": [
27 | {
28 | "keyData": "${ssh_key}"
29 | }
30 | ]
31 | }
32 | },
33 | "servicePrincipalProfile": {
34 | "servicePrincipalClientID": "${service_principle_client_id}",
35 | "servicePrincipalClientSecret": "${service_principle_client_secret}"
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/3-as-code/k8s.tfvars:
--------------------------------------------------------------------------------
1 | azure_subscription_id = ""
2 | azure_tenant_id = ""
3 | azure_client_id = ""
4 | azure_client_secret = ""
5 |
6 | dns_prefix = ""
7 | ssh_key = ""
8 |
--------------------------------------------------------------------------------
/3-as-code/main.tf:
--------------------------------------------------------------------------------
1 | provider "azurerm" {
2 | subscription_id = "${var.azure_subscription_id}"
3 | client_id = "${var.azure_client_id}"
4 | client_secret = "${var.azure_client_secret}"
5 | tenant_id = "${var.azure_tenant_id}"
6 | }
7 |
8 | # Azure Resource Group
9 | resource "azurerm_resource_group" "default" {
10 | name = "${var.resource_group_name}"
11 | location = "${var.azure_location}"
12 | }
13 |
14 | # Azure Virtual Network
15 | resource "azurerm_virtual_network" "default" {
16 | name = "${var.virtualnetworkname}"
17 | address_space = ["${var.cidr}"]
18 | location = "${var.azure_location}"
19 | resource_group_name = "${var.resource_group_name}"
20 | depends_on = ["azurerm_resource_group.default"]
21 | }
22 |
23 | # Azure Virtual Network -> Subnet
24 | resource "azurerm_subnet" "default" {
25 | name = "${var.virtualnetworkname}_subnet"
26 | resource_group_name = "${var.resource_group_name}"
27 | virtual_network_name = "${azurerm_virtual_network.default.name}"
28 | address_prefix = "${var.cidr_subnet}"
29 | depends_on = ["azurerm_virtual_network.default"]
30 | }
31 |
32 | output "virtualnetwork_subnet_default_id" {
33 | value = "${azurerm_subnet.default.id}"
34 | }
35 |
36 | # ACS Engine Config
37 | data "template_file" "acs_engine_config" {
38 | template = "${file(var.acs_engine_config_file)}"
39 |
40 | vars {
41 | master_vm_count = "${var.master_vm_count}"
42 | dns_prefix = "${var.dns_prefix}"
43 | vm_size = "${var.vm_size}"
44 | subnet_id = "${azurerm_subnet.default.id}"
45 | first_master_ip = "${var.first_master_ip}"
46 | worker_vm_count = "${var.worker_vm_count}"
47 | admin_user = "${var.admin_user}"
48 | ssh_key = "${var.ssh_key}"
49 | service_principle_client_id = "${var.azure_client_id}"
50 | service_principle_client_secret = "${var.azure_client_secret}"
51 | }
52 |
53 | depends_on = ["azurerm_subnet.default"]
54 | }
55 |
56 | # Locally output the rendered ACS Engine Config (after substitution has been performed)
57 | resource "null_resource" "render_acs_engine_config" {
58 | provisioner "local-exec" {
59 | command = "echo '${data.template_file.acs_engine_config.rendered}' > ${var.acs_engine_config_file_rendered}"
60 | }
61 |
62 | depends_on = ["data.template_file.acs_engine_config"]
63 | }
64 |
65 | # Locally run the ACS Engine to produce the Azure Resource Template for the K8s cluster
66 | resource "null_resource" "run_acs_engine" {
67 | provisioner "local-exec" {
68 | command = "acs-engine generate ${var.acs_engine_config_file_rendered}"
69 | }
70 |
71 | depends_on = ["null_resource.render_acs_engine_config"]
72 | }
73 |
74 | # Locally run the Azure 2.0 CLI to create the resource deployment
75 | resource "null_resource" "deploy_acs" {
76 | provisioner "local-exec" {
77 | command = "az group deployment create --name ${var.cluster_name} --resource-group ${var.resource_group_name} --template-file ./$(find _output -name 'azuredeploy.json') --parameters @./$(find _output -name 'azuredeploy.parameters.json')"
78 | }
79 |
80 | depends_on = ["null_resource.run_acs_engine"]
81 | }
82 |
83 | # Locally run the Azure 2.0 CLI to fix the routes
84 | resource "null_resource" "fix_routetable" {
85 | provisioner "local-exec" {
86 | command = "az network vnet subnet update --name ${azurerm_subnet.default.name} --resource-group ${var.resource_group_name} --vnet-name ${azurerm_virtual_network.default.name} --route-table $(az resource list --resource-group ${var.resource_group_name} --resource-type Microsoft.Network/routeTables | jq -r '.[] | .id')"
87 | }
88 |
89 | depends_on = ["null_resource.deploy_acs"]
90 | }
91 |
--------------------------------------------------------------------------------
/3-as-code/variables.tf:
--------------------------------------------------------------------------------
1 | variable "azure_subscription_id" {
2 | description = "Azure Subscription ID"
3 | }
4 |
5 | variable "azure_client_id" {
6 | description = "Azure Client ID"
7 | }
8 |
9 | variable "azure_client_secret" {
10 | description = "Azure Client Secret"
11 | }
12 |
13 | variable "azure_tenant_id" {
14 | description = "Azure Tenant ID"
15 | }
16 |
17 | variable "azure_location" {
18 | description = "Azure Location, e.g. North Europe"
19 | default = "North Europe"
20 | }
21 |
22 | variable "resource_group_name" {
23 | description = "Azure Resource Group Name"
24 | default = "k8sexample"
25 | }
26 |
27 | variable "virtualnetworkname" {
28 | description = "Name of the virtual network"
29 | default = "k8sexample_vnet"
30 | }
31 |
32 | variable "cidr" {
33 | description = "CIDR range of the VPC"
34 | default = "172.20.0.0/16"
35 | }
36 |
37 | variable "cidr_subnet" {
38 | description = "CIDR range of the only subnet in the VPC"
39 | default = "172.20.10.0/24"
40 | }
41 |
42 | variable "acs_engine_config_file" {
43 | description = "File name and location of the ACS Engine config file"
44 | default = "k8s.json"
45 | }
46 |
47 | variable "acs_engine_config_file_rendered" {
48 | description = "File name and location of the ACS Engine config file"
49 | default = "k8s_rendered.json"
50 | }
51 |
52 | variable "master_vm_count" {
53 | description = "Number of master VMs to create"
54 | default = 1
55 | }
56 |
57 | variable "dns_prefix" {
58 | description = "DNS prefix for the cluster"
59 | }
60 |
61 | variable "vm_size" {
62 | description = "Azure VM type"
63 | default = "Standard_A2"
64 | }
65 |
66 | variable "first_master_ip" {
67 | description = "First consecutive IP address to be assigned to master nodes"
68 | default = "172.20.10.10"
69 | }
70 |
71 | variable "worker_vm_count" {
72 | description = "Number of worker VMs to initially create"
73 | default = 1
74 | }
75 |
76 | variable "admin_user" {
77 | description = "Administrative username for the VMs"
78 | default = "azureuser"
79 | }
80 |
81 | variable "ssh_key" {
82 | description = "SSH public key in PEM format to apply to VMs"
83 | }
84 |
85 | variable "cluster_name" {
86 | description = "Name of the K8s cluster"
87 | default = "k8sexample-cluster"
88 | }
89 |
--------------------------------------------------------------------------------
/4-as-software/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krisnova/cloud-native-infrastructure-demo/57a9d6fc87e6aa3fc12d41c47eeb32720587f109/4-as-software/README.md
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Cloud Native Infrastructure
2 |
3 | ### Representing infrastructure
4 |
5 | Various ways of representing and mutating infrastructure.
6 |
7 | #### Infrastructure as a diagram
8 |
9 | Using a technical diagram to share intended infrastructure topologies with other humans. [More information](/1-as-diagram/README.md)
10 |
11 | #### Infrastructure as a script
12 |
13 | Using a uni-directional script to mutate infrastructure topologies and using the script as a way to mutate infrastructure. [More information](/2-as-script/README.md)
14 |
15 | #### Infrastructure as code
16 |
17 | Using standardized templating to represent infrastructure. The templating can be interpolated, and contain logic. [More information](/3-as-code/README.md)
18 |
19 | #### Infrastructure as software
20 |
21 | Infrastructure is managed by a residual piece of software over time. In order to mutate infrastructure, the software must be running. [More information](/4-as-software)
22 |
--------------------------------------------------------------------------------