mirror of
https://github.com/status-im/infra-swarm.git
synced 2025-02-22 12:28:11 +00:00
apply the elastic IP fix for Alibaba Cloud
This commit is contained in:
parent
9571bd8b5e
commit
20874c92fd
@ -26,10 +26,20 @@ resource "alicloud_security_group" "host" {
|
||||
vpc_id = "${data.alicloud_vpcs.host.vpcs.0.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "host" {
|
||||
/* WARNING: Using 'all' protocol fucks with port_range option */
|
||||
resource "alicloud_security_group_rule" "tcp" {
|
||||
security_group_id = "${alicloud_security_group.host.id}"
|
||||
type = "ingress"
|
||||
ip_protocol = "all"
|
||||
ip_protocol = "tcp"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
port_range = "${replace(element(local.open_ports, count.index), "-", "/")}"
|
||||
count = "${length(local.open_ports)}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "udp" {
|
||||
security_group_id = "${alicloud_security_group.host.id}"
|
||||
type = "ingress"
|
||||
ip_protocol = "udp"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
port_range = "${replace(element(local.open_ports, count.index), "-", "/")}"
|
||||
count = "${length(local.open_ports)}"
|
||||
@ -50,8 +60,8 @@ resource "alicloud_instance" "host" {
|
||||
|
||||
tags = {
|
||||
stage = "${local.stage}"
|
||||
group = "${var.group}"
|
||||
env = "${var.env}"
|
||||
group = "${var.group}"
|
||||
env = "${var.env}"
|
||||
}
|
||||
|
||||
key_name = "${var.key_pair}"
|
||||
@ -59,26 +69,46 @@ resource "alicloud_instance" "host" {
|
||||
instance_type = "${var.type}"
|
||||
system_disk_category = "${var.disk}"
|
||||
count = "${var.count}"
|
||||
internet_max_bandwidth_out = "${var.max_band_out}"
|
||||
|
||||
/* costs */
|
||||
instance_charge_type = "${var.charge}"
|
||||
period_unit = "${var.period}"
|
||||
|
||||
/* necessary because alicloud does not provide it */
|
||||
/* https://github.com/radekg/terraform-provisioner-ansible/issues/54 */
|
||||
connection {
|
||||
host = "${self.public_ip}"
|
||||
}
|
||||
/* NOTE: We provision inside Elastic IP association */
|
||||
}
|
||||
|
||||
/* bootstraping access for later Ansible use */
|
||||
resource "alicloud_eip" "host" {
|
||||
count = "${var.count}"
|
||||
lifecycle = { prevent_destroy = true }
|
||||
}
|
||||
|
||||
/**
|
||||
* WARNING: This is broken when instance has a public_ip
|
||||
* https://www.alibabacloud.com/help/doc-detail/72125.htm
|
||||
* "The ECS instance does not have a public IP, nor is it bound to any EIP."
|
||||
* https://www.terraform.io/docs/providers/alicloud/r/eip_association.html
|
||||
**/
|
||||
resource "alicloud_eip_association" "host" {
|
||||
allocation_id = "${element(alicloud_eip.host.*.id, count.index)}"
|
||||
instance_id = "${element(alicloud_instance.host.*.id, count.index)}"
|
||||
count = "${var.count}"
|
||||
|
||||
/**
|
||||
* It is necessary to provision here instead of in alicloud_instance
|
||||
* because Alibaba Cloud instances do not have public IPs by default
|
||||
**/
|
||||
provisioner "ansible" {
|
||||
connection {
|
||||
host = "${element(alicloud_eip.host.*.ip_address, count.index)}"
|
||||
user = "${var.ssh_user}"
|
||||
}
|
||||
|
||||
local = "yes"
|
||||
plays {
|
||||
playbook = "${path.cwd}/ansible/bootstrap.yml"
|
||||
playbook = "./ansible/bootstrap.yml"
|
||||
groups = ["${var.group}"]
|
||||
extra_vars = {
|
||||
hostname = "${var.name}-${format("%02d", count.index+1)}.${local.dc}.${var.env}.${local.stage}"
|
||||
hostname = "${element(alicloud_instance.host.*.host_name, count.index)}"
|
||||
ansible_ssh_user = "${var.ssh_user}"
|
||||
data_center = "${local.dc}"
|
||||
stage = "${local.stage}"
|
||||
@ -88,22 +118,11 @@ resource "alicloud_instance" "host" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "alicloud_eip" "host" {
|
||||
count = "${var.count}"
|
||||
/*lifecycle = { prevent_destroy = true }*/
|
||||
}
|
||||
|
||||
resource "alicloud_eip_association" "host" {
|
||||
allocation_id = "${element(alicloud_eip.host.*.id, count.index)}"
|
||||
instance_id = "${element(alicloud_instance.host.*.id, count.index)}"
|
||||
count = "${var.count}"
|
||||
}
|
||||
|
||||
resource "cloudflare_record" "host" {
|
||||
domain = "${var.domain}"
|
||||
count = "${var.count}"
|
||||
name = "${element(alicloud_instance.host.*.host_name, count.index)}"
|
||||
value = "${element(alicloud_eip.host.ip_address, count.index)}"
|
||||
value = "${element(alicloud_eip.host.*.ip_address, count.index)}"
|
||||
type = "A"
|
||||
ttl = 3600
|
||||
}
|
||||
@ -113,7 +132,7 @@ resource "ansible_host" "host" {
|
||||
groups = ["${var.group}", "${local.dc}"]
|
||||
count = "${var.count}"
|
||||
vars {
|
||||
ansible_host = "${element(alicloud_eip.host.ip_address, count.index)}"
|
||||
ansible_host = "${element(alicloud_eip.host.*.ip_address, count.index)}"
|
||||
hostname = "${element(alicloud_instance.host.*.host_name, count.index)}"
|
||||
region = "${element(alicloud_instance.host.*.availability_zone, count.index)}"
|
||||
dns_entry = "${element(alicloud_instance.host.*.host_name, count.index)}.${var.domain}"
|
||||
|
@ -1,5 +1,9 @@
|
||||
/* SCALING --------------------------------------*/
|
||||
|
||||
variable count {
|
||||
description = "Number of instances to start in this region."
|
||||
}
|
||||
|
||||
variable image {
|
||||
/**
|
||||
* This image is created with Packer because Alicloud does not provide one
|
||||
@ -29,10 +33,6 @@ variable max_band_out {
|
||||
default = 30
|
||||
}
|
||||
|
||||
variable count {
|
||||
description = "Number of instances to start in this region."
|
||||
}
|
||||
|
||||
/* FIREWALL -------------------------------------*/
|
||||
|
||||
variable open_ports {
|
||||
|
Loading…
x
Reference in New Issue
Block a user