Commit 943ef20b authored by Daniele Valeriani's avatar Daniele Valeriani Committed by John Jarvis

Create a shared redis module that we can use for any type

parent c47485ab
......@@ -16,6 +16,16 @@ variable "first_user_username" {}
variable "first_user_password" {}
# These are the new variables to connect to the newly created instance, which
# replace the two above.
variable "ssh_user" {}
variable "ssh_private_key" {}
variable "ssh_public_key" {}
# This must be removed after porting all the modules to the private/public keys
variable "ssh_key" {}
variable "location" {
default = "East US 2"
}
......@@ -262,6 +272,29 @@ module "virtual-machines-redis" {
gitlab_com_zone_id = "${var.gitlab_com_zone_id}"
}
module "virtual-machines-redis-cache" {
address_prefix = "${module.subnet-redis.address_prefix}"
chef_repo_dir = "${var.chef_repo_dir}"
chef_vaults = "syslog_client gitlab-staging-base gitlab_consul:stg_client"
chef_version = "${var.chef_version}"
environment = "${var.environment}"
gitlab_com_zone_id = "${var.gitlab_com_zone_id}"
ip_skew = 10
location = "${var.location}"
persistence = "cache"
redis_count = 1
redis_instance_type = "Standard_DS2_v2"
resource_group_name = "${module.subnet-redis.resource_group_name}"
sentinel_count = 3
sentinel_instance_type = "Standard_A1_v2"
source = "../../modules/virtual-machines/redis"
ssh_private_key = "${var.ssh_private_key}"
ssh_public_key = "${var.ssh_public_key}"
ssh_user = "${var.ssh_user}"
subnet_id = "${module.subnet-redis.subnet_id}"
tier = "db"
}
module "virtual-machines-elasticsearch" {
count = 0
source = "virtual-machines/elasticsearch"
......
......@@ -33,16 +33,16 @@ resource "aws_route53_record" "api" {
data "template_file" "chef-bootstrap-api" {
count = "${var.count}"
template = "${file("${path.root}/../../templates/chef-bootstrap-packer.tpl")}"
template = "${file("${path.root}/../../templates/chef-bootstrap-ssh-keys.tpl")}"
vars {
ip_address = "${azurerm_network_interface.api.*.private_ip_address[count.index]}"
hostname = "${format("api-%02d.%v.%v.gitlab.com", count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
chef_version = "${var.chef_version}"
chef_repo_dir = "${var.chef_repo_dir}"
ssh_user = "${var.ssh_user}"
ssh_key = "${var.ssh_key}"
chef_vaults = "${var.chef_vaults}"
ip_address = "${azurerm_network_interface.api.*.private_ip_address[count.index]}"
hostname = "${format("api-%02d.%v.%v.gitlab.com", count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
chef_version = "${var.chef_version}"
chef_repo_dir = "${var.chef_repo_dir}"
ssh_user = "${var.ssh_user}"
ssh_private_key = "${var.ssh_key}"
chef_vaults = "${var.chef_vaults}"
}
}
......
......@@ -33,16 +33,16 @@ resource "aws_route53_record" "git" {
data "template_file" "chef-bootstrap-git" {
count = "${var.count}"
template = "${file("${path.root}/../../templates/chef-bootstrap-packer.tpl")}"
template = "${file("${path.root}/../../templates/chef-bootstrap-ssh-keys.tpl")}"
vars {
ip_address = "${azurerm_network_interface.git.*.private_ip_address[count.index]}"
hostname = "${format("git-%02d.%v.%v.gitlab.com", count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
chef_version = "${var.chef_version}"
chef_repo_dir = "${var.chef_repo_dir}"
ssh_user = "${var.ssh_user}"
ssh_key = "${var.ssh_key}"
chef_vaults = "${var.chef_vaults}"
ip_address = "${azurerm_network_interface.git.*.private_ip_address[count.index]}"
hostname = "${format("git-%02d.%v.%v.gitlab.com", count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
chef_version = "${var.chef_version}"
chef_repo_dir = "${var.chef_repo_dir}"
ssh_user = "${var.ssh_user}"
ssh_private_key = "${var.ssh_key}"
chef_vaults = "${var.chef_vaults}"
}
}
......
resource "azurerm_availability_set" "redis" {
name = "${format("redis-%v-%v", var.persistence, var.environment)}"
location = "${var.location}"
managed = true
platform_update_domain_count = 20
platform_fault_domain_count = 3
resource_group_name = "${var.resource_group_name}"
}
resource "azurerm_network_interface" "redis" {
count = "${var.redis_count}"
name = "${format("redis-%v-%02d-%v-%v", var.persistence, count.index + 1, var.tier, var.environment)}"
internal_dns_name_label = "${format("redis-%v-%02d-%v-%v", var.persistence, count.index + 1, var.tier, var.environment)}"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
ip_configuration {
name = "${format("redis-%v-%02d-%v", var.persistence, count.index + 1, var.environment)}"
subnet_id = "${var.subnet_id}"
private_ip_address_allocation = "static"
private_ip_address = "${join(".", slice(split(".", var.address_prefix), 0, 3))}.${count.index + var.ip_skew + 1}"
}
}
resource "aws_route53_record" "redis" {
count = "${var.redis_count}"
zone_id = "${var.gitlab_com_zone_id}"
name = "${format("redis-%v-%02d.%v.%v.gitlab.com.", var.persistence, count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
type = "A"
ttl = "300"
records = ["${azurerm_network_interface.redis.*.private_ip_address[count.index]}"]
}
data "template_file" "chef-bootstrap-redis" {
count = "${var.redis_count}"
template = "${file("${path.root}/../../templates/chef-bootstrap-ssh-keys.tpl")}"
vars {
chef_repo_dir = "${var.chef_repo_dir}"
chef_vaults = "${var.chef_vaults}"
chef_version = "${var.chef_version}"
hostname = "${format("redis-%v-%02d.%v.%v.gitlab.com", var.persistence, count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
ip_address = "${azurerm_network_interface.redis.*.private_ip_address[count.index]}"
ssh_private_key = "${var.ssh_private_key}"
ssh_user = "${var.ssh_user}"
}
}
resource "azurerm_virtual_machine" "redis" {
count = "${var.redis_count}"
name = "${format("redis-%v-%02d.%v.%v.gitlab.com", var.persistence, count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
availability_set_id = "${azurerm_availability_set.redis.id}"
network_interface_ids = ["${azurerm_network_interface.redis.*.id[count.index]}"]
primary_network_interface_id = "${azurerm_network_interface.redis.*.id[count.index]}"
vm_size = "${var.redis_instance_type}"
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "${format("osdisk-redis-%v-%02d-%v", var.persistence, count.index + 1, var.environment)}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
storage_data_disk {
name = "${format("data-redis-%v-%02d-%v", var.persistence, count.index + 1, var.environment)}"
managed_disk_type = "Premium_LRS"
create_option = "Empty"
lun = 0
disk_size_gb = "20"
}
os_profile {
computer_name = "${format("redis-%v-%02d.%v.%v.gitlab.com", var.persistence, count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
admin_username = "${var.ssh_user}"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys = {
path = "/home/${var.ssh_user}/.ssh/authorized_keys"
key_data = "${file("${var.ssh_public_key}")}"
}
}
provisioner "local-exec" {
command = "${data.template_file.chef-bootstrap-redis.*.rendered[count.index]}"
}
provisioner "remote-exec" {
inline = ["nohup bash -c 'sudo chef-client &'"]
connection {
type = "ssh"
host = "${azurerm_network_interface.redis.*.private_ip_address[count.index]}"
user = "${var.ssh_user}"
private_key = "${file("${var.ssh_private_key}")}"
timeout = "10s"
}
}
}
resource "azurerm_availability_set" "sentinel" {
name = "${format("sentinel-%v-%v", var.persistence, var.environment)}"
location = "${var.location}"
managed = true
platform_update_domain_count = 20
platform_fault_domain_count = 3
resource_group_name = "${var.resource_group_name}"
}
resource "azurerm_network_interface" "sentinel" {
count = "${var.sentinel_count}"
name = "${format("sentinel-%v-%02d-%v-%v", var.persistence, count.index + 1, var.tier, var.environment)}"
internal_dns_name_label = "${format("sentinel-%v-%02d-%v-%v", var.persistence, count.index + 1, var.tier, var.environment)}"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
ip_configuration {
name = "${format("sentinel-%v-%02d-%v", var.persistence, count.index + 1, var.environment)}"
subnet_id = "${var.subnet_id}"
private_ip_address_allocation = "static"
private_ip_address = "${join(".", slice(split(".", var.address_prefix), 0, 3))}.${count.index + var.ip_skew + 11}"
}
}
resource "aws_route53_record" "sentinel" {
count = "${var.sentinel_count}"
zone_id = "${var.gitlab_com_zone_id}"
name = "${format("sentinel-%v-%02d.%v.%v.gitlab.com.", var.persistence, count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
type = "A"
ttl = "300"
records = ["${azurerm_network_interface.sentinel.*.private_ip_address[count.index]}"]
}
data "template_file" "chef-bootstrap-sentinel" {
count = "${var.sentinel_count}"
template = "${file("${path.root}/../../templates/chef-bootstrap-ssh-keys.tpl")}"
vars {
ip_address = "${azurerm_network_interface.sentinel.*.private_ip_address[count.index]}"
hostname = "${format("sentinel-%v-%02d.%v.%v.gitlab.com", var.persistence, count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
chef_repo_dir = "${var.chef_repo_dir}"
ssh_user = "${var.ssh_user}"
ssh_private_key = "${var.ssh_private_key}"
chef_vaults = "${var.chef_vaults}"
chef_version = "${var.chef_version}"
}
}
resource "azurerm_virtual_machine" "sentinel" {
count = "${var.sentinel_count}"
name = "${format("sentinel-%v-%02d.%v.%v.gitlab.com", var.persistence, count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
availability_set_id = "${azurerm_availability_set.sentinel.id}"
network_interface_ids = ["${azurerm_network_interface.sentinel.*.id[count.index]}"]
primary_network_interface_id = "${azurerm_network_interface.sentinel.*.id[count.index]}"
vm_size = "${var.sentinel_instance_type}"
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "${format("osdisk-sentinel-%v-%02d-%v", var.persistence, count.index + 1, var.environment)}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "${format("sentinel-%v-%02d.%v.%v.gitlab.com", var.persistence, count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
admin_username = "${var.ssh_user}"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys = {
path = "/home/${var.ssh_user}/.ssh/authorized_keys"
key_data = "${file("${var.ssh_public_key}")}"
}
}
provisioner "local-exec" {
command = "${data.template_file.chef-bootstrap-sentinel.*.rendered[count.index]}"
}
provisioner "remote-exec" {
inline = ["nohup bash -c 'sudo chef-client &'"]
connection {
type = "ssh"
host = "${azurerm_network_interface.sentinel.*.private_ip_address[count.index]}"
user = "${var.ssh_user}"
private_key = "${file("${var.ssh_private_key}")}"
timeout = "10s"
}
}
}
variable "address_prefix" {}
variable "chef_repo_dir" {}
variable "chef_vaults" {}
variable "chef_version" {}
variable "environment" {}
variable "gitlab_com_zone_id" {}
variable "ip_skew" {}
variable "location" {}
variable "persistence" {}
variable "redis_count" {}
variable "redis_instance_type" {}
variable "resource_group_name" {}
variable "sentinel_count" {}
variable "sentinel_instance_type" {}
variable "ssh_private_key" {}
variable "ssh_public_key" {}
variable "ssh_user" {}
variable "subnet_id" {}
variable "tier" {}
......@@ -33,16 +33,16 @@ resource "aws_route53_record" "web" {
data "template_file" "chef-bootstrap-web" {
count = "${var.count}"
template = "${file("${path.root}/../../templates/chef-bootstrap-packer.tpl")}"
template = "${file("${path.root}/../../templates/chef-bootstrap-ssh-keys.tpl")}"
vars {
ip_address = "${azurerm_network_interface.web.*.private_ip_address[count.index]}"
hostname = "${format("web-%02d.%v.%v.gitlab.com", count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
chef_version = "${var.chef_version}"
chef_repo_dir = "${var.chef_repo_dir}"
ssh_user = "${var.ssh_user}"
ssh_key = "${var.ssh_key}"
chef_vaults = "${var.chef_vaults}"
ip_address = "${azurerm_network_interface.web.*.private_ip_address[count.index]}"
hostname = "${format("web-%02d.%v.%v.gitlab.com", count.index + 1, var.tier, var.environment == "prod" ? "prd" : var.environment)}"
chef_version = "${var.chef_version}"
chef_repo_dir = "${var.chef_repo_dir}"
ssh_user = "${var.ssh_user}"
ssh_private_key = "${var.ssh_key}"
chef_vaults = "${var.chef_vaults}"
}
}
......
......@@ -3,7 +3,7 @@ set -eu
cd ${chef_repo_dir}
bundle exec knife bootstrap ${ssh_user}@${ip_address} \
--ssh-identity-file ${ssh_key} \
--ssh-identity-file ${ssh_private_key} \
--no-host-key-verify \
--sudo \
--node-name ${hostname} \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment