|
| 1 | + |
| 2 | +resource "aws_instance" "client" { |
| 3 | + count = "${var.client_instance_count}" |
| 4 | + ami = "${var.instance_ami}" |
| 5 | + instance_type = "${var.client_instance_type}" |
| 6 | + subnet_id = data.terraform_remote_state.shared_resources.outputs.subnet_public_id |
| 7 | + vpc_security_group_ids = ["${data.terraform_remote_state.shared_resources.outputs.performance_cto_sg_id}"] |
| 8 | + key_name = "${var.key_name}" |
| 9 | + |
| 10 | + root_block_device { |
| 11 | + volume_size = "${var.instance_volume_size}" |
| 12 | + volume_type = "${var.instance_volume_type}" |
| 13 | + encrypted = "${var.instance_volume_encrypted}" |
| 14 | + delete_on_termination = true |
| 15 | + } |
| 16 | + |
| 17 | + volume_tags = { |
| 18 | + Name = "ebs_block_device-${var.setup_name}-CLIENT-${count.index + 1}" |
| 19 | + setup = "${var.setup_name}" |
| 20 | + triggering_env = "${var.triggering_env}" |
| 21 | + github_actor = "${var.github_actor}" |
| 22 | + github_org = "${var.github_org}" |
| 23 | + github_repo = "${var.github_repo}" |
| 24 | + github_sha = "${var.github_sha}" |
| 25 | + } |
| 26 | + |
| 27 | + tags = { |
| 28 | + Name = "${var.setup_name}-CLIENT-${count.index + 1}" |
| 29 | + setup = "${var.setup_name}" |
| 30 | + triggering_env = "${var.triggering_env}" |
| 31 | + github_actor = "${var.github_actor}" |
| 32 | + github_org = "${var.github_org}" |
| 33 | + github_repo = "${var.github_repo}" |
| 34 | + github_sha = "${var.github_sha}" |
| 35 | + } |
| 36 | + |
| 37 | + ################################################################################ |
| 38 | + # This will ensure we wait here until the instance is ready to receive the ssh connection |
| 39 | + ################################################################################ |
| 40 | + provisioner "remote-exec" { |
| 41 | + script = "./../scripts/wait_for_instance.sh" |
| 42 | + connection { |
| 43 | + host = "${self.public_ip}" # The `self` variable is like `this` in many programming languages |
| 44 | + type = "ssh" # in this case, `self` is the resource (the server). |
| 45 | + user = "${var.ssh_user}" |
| 46 | + private_key = "${file(var.private_key)}" |
| 47 | + #need to increase timeout to larger then 5m for metal instances |
| 48 | + timeout = "15m" |
| 49 | + agent = "false" |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + ################################################################################ |
| 54 | + # Deployment related |
| 55 | + ################################################################################ |
| 56 | +} |
0 commit comments