Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of Azure Resource Manager provider terraform configuration #704

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
bf95e21
Add new azure resorce manager branch and privider terraform file
Apr 27, 2016
690b73f
Addition of terraform variables file
Apr 27, 2016
d2d5649
Rename folder to azurerm
Apr 27, 2016
51c370d
Addition of virtual network and storage account
Apr 28, 2016
3aedd81
Addition bastion server and master servers configuration
Apr 28, 2016
809a9c9
updates and addition of slave server configuration
Apr 29, 2016
1c53919
Merge branch 'master' into azure_rmprovider
May 6, 2016
6b79f6c
update slave references to agent
May 6, 2016
57e9c82
Updates to run remote execution scripts on server
May 9, 2016
cd19c54
update remote-exec to use certificate authentication, requires Terraf…
May 10, 2016
5274c5b
Add new azure resorce manager branch and privider terraform file
Apr 27, 2016
9298210
Addition of terraform variables file
Apr 27, 2016
63028d1
Rename folder to azurerm
Apr 27, 2016
f778e83
Addition of virtual network and storage account
Apr 28, 2016
88c2bd8
Addition bastion server and master servers configuration
Apr 28, 2016
974d0fa
updates and addition of slave server configuration
Apr 29, 2016
d8e04d6
update slave references to agent
May 6, 2016
15cda48
Updates to run remote execution scripts on server
May 9, 2016
be8a3d4
update remote-exec to use certificate authentication, requires Terraf…
May 10, 2016
72c737a
Merge branch 'azure_rmprovider' of https://github.com/heywoodj/Apollo…
May 10, 2016
0eac48b
Merge branch 'master' into azure_rmprovider
May 10, 2016
92f594a
Clean up formatting
May 10, 2016
522d7c7
Clean up formatting
May 10, 2016
c0f64c7
Clean up formatting
May 10, 2016
432f10b
Merge branch 'master' into azure_rmprovider
May 16, 2016
7f35c1e
Move into 'private-cloud' folder
May 16, 2016
a6c68cb
Update to configure VM's through bastion host
May 16, 2016
53dc1e1
Update servers to copy files from correct location.
May 16, 2016
5ae33fc
Fix format issue.
May 16, 2016
a8142a7
Fix format issue.
May 16, 2016
12effba
Inclusion of cloud config and seperation of subnets
May 17, 2016
d7412d9
Fix format issues
May 17, 2016
0af0c9d
Fix format issues
May 17, 2016
712d630
Update to create bastion security group
May 18, 2016
cf8eb3f
Fix formatting
May 18, 2016
0ebb252
Fix formatting
May 18, 2016
2f65fa9
Addition of public azure infrastructure
May 23, 2016
a0ca621
Fix formatting
May 23, 2016
24423d4
Addition of route tables and gateway
May 25, 2016
9b57654
Fix formatting
May 25, 2016
ba9c292
Create README.md
May 26, 2016
0c2dc51
Delete README.md
May 26, 2016
8587ef0
Create README.md
May 26, 2016
9eba56a
Update README.md
May 26, 2016
8161be6
Update README.md
May 26, 2016
b573442
Update README.md
May 26, 2016
e7713af
Update README.md
May 26, 2016
b0e357f
Update README.md
May 26, 2016
76e8517
update path to script files
May 26, 2016
25ff003
Merge branch 'azure_rmprovider' of https://github.com/heywoodj/Apollo…
May 26, 2016
726d104
Update README.md
May 26, 2016
2ee172a
Update README.md
May 26, 2016
e08dd7a
Create README.md
May 26, 2016
7baefff
Add images folder
May 31, 2016
7cea6d7
Update README.md
May 31, 2016
4be2738
Update README.md
May 31, 2016
81c8910
Update README.md
May 31, 2016
f484bd4
Delete README.md
May 31, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions terraform/azurerm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Azure Resource Manager terraform configuration
---------------------------------------------------

This folder contains the terraform configuration for a public and private infrastructure provisioned in Azure and is created by attempting to reverse engineering and match the existing AWS architecture, https://github.com/Capgemini/Apollo/tree/master/terraform/aws.

The configuration is based on Terraform's ARM provider found here, https://www.terraform.io/docs/providers/azurerm/index.html.
Before Terrafom can create infrastructure within your Azure subscription the following information is required by the 'provider.tf' file including, subscription id, client id, client secret, tenant id. To set up oAuth authentication follow this guide https://www.terraform.io/docs/providers/azurerm/index.html.

Connection to the server instances is via ssh authenticated by a public / private key certificate in openssh format. Putty was used to generate the public / private key files. There was an issue with certificate only authentication **so please use Terraform verion v0.6.16 or higher**.

The infrastructure is configured inline with the ARM architecture as shown in the diagram below. Terraform does not yet support creating Load Balance resources thus it was not possible to replicate this feature from AWS.

![architecture](images/ARMArchitecture.png)
Binary file added terraform/azurerm/images/ARMArchitecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions terraform/azurerm/private-cloud/agent-cloud-config.yml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#cloud-config

coreos:
units:
- name: format-ebs-volume.service
command: start
content: |
[Unit]
Description=Formats the ebs volume if needed
Before=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c '(/usr/sbin/blkid -t TYPE=ext4 | grep /dev/xvdb) || (/usr/sbin/wipefs -fa /dev/xvdb && /usr/sbin/mkfs.ext4 /dev/xvdb)'
- name: var-lib-docker.mount
command: start
content: |
[Unit]
Description=Mount ephemeral to /var/lib/docker
Requires=format-ebs-volume.service
After=format-ebs-volume.service
[Mount]
What=/dev/xvdb
Where=/var/lib/docker
Type=ext4
- name: docker.service
drop-ins:
- name: 10-wait-docker.conf
content: |
[Unit]
After=var-lib-docker.mount
Requires=var-lib-docker.mount
etcd2:
proxy: on
listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001
discovery: ${etcd_discovery_url}
fleet:
metadata: "role=agent,region=${region}"
public-ip: "$public_ipv4"
etcd_servers: "http://localhost:2379"
locksmith:
endpoint: "http://localhost:2379"
units:
- name: etcd2.service
command: start
update:
reboot-strategy: best-effort
manage_etc_hosts: localhost
20 changes: 20 additions & 0 deletions terraform/azurerm/private-cloud/bastion-cloud-config.yml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#cloud-config

coreos:
etcd2:
proxy: on
listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001
discovery: ${etcd_discovery_url}
fleet:
metadata: "role=bastion,region=${region}"
etcd_servers: "http://localhost:2379"
locksmith:
endpoint: "http://localhost:2379"
units:
- name: docker.service
command: start
- name: etcd2.service
command: start
update:
reboot-strategy: best-effort
manage_etc_hosts: localhost
20 changes: 20 additions & 0 deletions terraform/azurerm/private-cloud/bastion-publicip.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Create Public IP Address for bastion server
resource "azurerm_public_ip" "bastion_publicip" {
name = "BastionPublicIp"
location = "${var.region}"
resource_group_name = "${azurerm_resource_group.resource_group.name}"
public_ip_address_allocation = "static"
}

#Output
output "bastion_publicip_id" {
value = "${azurerm_public_ip.bastion_publicip.id}"
}

output "bastion_publicip_ipaddress" {
value = "${azurerm_public_ip.bastion_publicip.ip_address}"
}

output "bastion_publicip_fqdn" {
value = "${azurerm_public_ip.bastion_publicip.fqdn}"
}
63 changes: 63 additions & 0 deletions terraform/azurerm/private-cloud/bastion-security-group.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#Create Network Security Group
resource "azurerm_network_security_group" "bastion_security_group" {
name = "AzureRM_NetworkSecurityGroup"
location = "${var.region}"
resource_group_name = "${azurerm_resource_group.resource_group.name}"

security_rule {
name = "AzureRM_SecurityRuleSSH"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}

security_rule {
name = "AzureRM_SecurityRuleOpenVPN"
priority = 101
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "1194"
source_address_prefix = "*"
destination_address_prefix = "*"
}

security_rule {
name = "AzureRM_SecurityRuleOpenHTTPS"
priority = 102
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = "*"
destination_address_prefix = "*"
}

security_rule {
name = "AzureRM_SecurityRuleOpenHTTP"
priority = 103
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
}

tags {
Name = "bastion-apollo-sg"
}
}

#Output
output "network_security_group_id" {
value = "${azurerm_network_security_group.bastion_security_group.id}"
}
128 changes: 128 additions & 0 deletions terraform/azurerm/private-cloud/bastion-server.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Create a network interface for bastion server
resource "azurerm_network_interface" "bastion_network_interface" {
name = "Bastion_NetworkInterface"
location = "${var.region}"
resource_group_name = "${azurerm_resource_group.resource_group.name}"
network_security_group_id = "${azurerm_network_security_group.bastion_security_group.id}"

ip_configuration {
name = "bastionipconfiguration"
subnet_id = "${element(azurerm_subnet.public.*.id, 0)}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${azurerm_public_ip.bastion_publicip.id}"
}
}

# User profile template
resource "template_file" "bastion_cloud_init" {
template = "${file("bastion-cloud-config.yml.tpl")}"
depends_on = ["template_file.etcd_discovery_url"]
vars {
etcd_discovery_url = "${file(var.etcd_discovery_url_file)}"
size = "${var.master_count}"
vpc_cidr_block = "${var.vpc_cidr_block}"
region = "${var.region}"
}
}

# NAT/VPN server
resource "azurerm_virtual_machine" "bastion" {
name = "apollo-bastion"
location = "${var.region}"
resource_group_name = "${azurerm_resource_group.resource_group.name}"
network_interface_ids = ["${azurerm_network_interface.bastion_network_interface.id}"]
vm_size = "${var.instance_type.bastion}"

storage_image_reference {
publisher = "${var.artifact_bastion.publisher}"
offer = "${var.artifact_bastion.offer}"
sku = "${var.artifact_bastion.sku}"
version = "${var.artifact_bastion.version}"
}

storage_os_disk {
name = "bastiondisk"
vhd_uri = "${azurerm_storage_account.storage_account.primary_blob_endpoint}${azurerm_storage_container.storage_container.name}/bastiondisk.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}

os_profile {
computer_name = "${var.bastion_server_computername}"
admin_username = "${var.bastion_server_username}"
admin_password = "${var.bastion_server_password}"
custom_data = "${base64encode(template_file.bastion_cloud_init.rendered)}"
}

os_profile_linux_config {
disable_password_authentication = true

ssh_keys {
path = "/home/${var.bastion_server_username}/.ssh/authorized_keys"
key_data = "${file("${var.ssh_public_key_file}")}" # openssh format
}
}

tags {
Name = "apollo-mesos-bastion"
role = "bastion"
}

connection {
host = "${azurerm_public_ip.bastion_publicip.ip_address}"
user = "${var.bastion_server_username}"
private_key = "${file("${var.ssh_private_key_file}")}" # openssh format
}

# Do some early bootstrapping of the CoreOS machines. This will install
# python and pip so we can use as the ansible_python_interpreter in our playbooks
provisioner "file" {
source = "../../scripts/coreos"
destination = "/tmp"
}

provisioner "remote-exec" {
inline = [
"sudo chmod -R +x /tmp/coreos",
"/tmp/coreos/bootstrap.sh",
"~/bin/python /tmp/coreos/get-pip.py",
"sudo mv /tmp/coreos/runner ~/bin/pip && sudo chmod 0755 ~/bin/pip",
"sudo rm -rf /tmp/coreos",

# Initialize open VPN container and server config
"sudo iptables -t nat -A POSTROUTING -j MASQUERADE",
"sudo docker run --name ovpn-data -v /etc/openvpn busybox",
"sudo docker run --volumes-from ovpn-data --rm gosuri/openvpn ovpn_genconfig -p ${var.vpc_cidr_block} -u udp://${azurerm_public_ip.bastion_publicip.ip_address}"
]
}
}

# Bastion network interface outputs
output "bastion_network_interface_id" {
value = "${azurerm_network_interface.bastion_network_interface.id}"
}

output "bastion_network_interface_macaddress" {
value = "${azurerm_network_interface.bastion_network_interface.mac_address}"
}

output "bastion_network_interface_privateipaddress" {
value = "${azurerm_network_interface.bastion_network_interface.private_ip_address}"
}

output "bastion_network_interface_virtualmachineid" {
value = "${azurerm_network_interface.bastion_network_interface.virtual_machine_id}"
}

output "bastion_network_interface_applieddnsservers" {
value = "${azurerm_network_interface.bastion_network_interface.applied_dns_servers}"
}

output "bastion_network_interface_internalfqdn" {
value = "${azurerm_network_interface.bastion_network_interface.internal_fqdn}"
}

# Bastion virtual machine outputs
output "bastion_virtual_machine_id" {
value = "${azurerm_virtual_machine.bastion.id}"
}
13 changes: 13 additions & 0 deletions terraform/azurerm/private-cloud/gateway-local-network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Create Public IP Address for local network gateway
resource "azurerm_local_network_gateway" "gateway" {
name = "AzureRM_LocalNetworkGateway"
resource_group_name = "${azurerm_resource_group.resource_group.name}"
location = "${var.region}"
gateway_address = "${azurerm_public_ip.bastion_publicip.ip_address}"
address_space = ["${var.vpc_cidr_block}"]
}

#Output
output "gateway_local_network_id" {
value = "${azurerm_local_network_gateway.gateway.id}"
}
22 changes: 22 additions & 0 deletions terraform/azurerm/private-cloud/master-cloud-config.yml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#cloud-config

coreos:
etcd2:
# $private_ipv4 is populated by the cloud provider
# we don't have a $public_ipv4 in the private VPC
advertise-client-urls: http://$private_ipv4:2379,http://$private_ipv4:4001
initial-advertise-peer-urls: http://$private_ipv4:2380
# listen on both the official ports and the legacy ports
# legacy ports can be omitted if your application doesn't depend on them
listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001
listen-peer-urls: http://$private_ipv4:2380,http://$private_ipv4:7001
# Discovery is populated by Terraform
discovery: ${etcd_discovery_url}
fleet:
metadata: "role=master,region=${region}"
units:
- name: etcd2.service
command: start
update:
reboot-strategy: best-effort
manage_etc_hosts: localhost
11 changes: 11 additions & 0 deletions terraform/azurerm/private-cloud/mesos-agents-availability-set.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Create an availability set for agent servers
resource "azurerm_availability_set" "agent" {
name = "Agent_AvailabilitySet"
resource_group_name = "${azurerm_resource_group.resource_group.name}"
location = "${var.region}"
}

# Mesos agent availability set outputs
output "mesos_agent_virtual_machine_ids" {
value = "${azurerm_availability_set.agent.id}"
}
Loading