1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: CC-BY-SA-3.0
6 required_version = "~> 1.3.0"
9 source = "hashicorp/aws"
16 region = local.region_name
18 tags = merge(local.custom_tags, {
19 Arvados = local.cluster_name
25 resource "aws_iam_instance_profile" "keepstore_instance_profile" {
26 name = "${local.cluster_name}-keepstore-00-iam-role"
27 role = data.terraform_remote_state.data-storage.outputs.keepstore_iam_role_name
30 resource "aws_iam_instance_profile" "compute_node_instance_profile" {
31 name = "${local.cluster_name}-compute-node-00-iam-role"
32 role = local.compute_node_iam_role_name
35 resource "aws_iam_instance_profile" "dispatcher_instance_profile" {
36 name = "${local.cluster_name}_dispatcher_instance_profile"
37 role = aws_iam_role.cloud_dispatcher_iam_role.name
40 resource "aws_secretsmanager_secret" "ssl_password_secret" {
41 name = local.ssl_password_secret_name
42 recovery_window_in_days = 0
45 resource "aws_iam_instance_profile" "default_instance_profile" {
46 name = "${local.cluster_name}_default_instance_profile"
47 role = aws_iam_role.default_iam_role.name
50 resource "aws_instance" "arvados_service" {
51 for_each = toset(concat(local.public_hosts, local.private_hosts))
52 ami = local.instance_ami_id
53 instance_type = try(var.instance_type[each.value], var.instance_type.default)
54 user_data = templatefile("user_data.sh", {
55 "hostname": each.value,
56 "deploy_user": var.deploy_user,
57 "ssh_pubkey": file(local.pubkey_path)
59 private_ip = local.private_ip[each.value]
60 subnet_id = contains(local.user_facing_hosts, each.value) ? local.public_subnet_id : local.private_subnet_id
61 vpc_security_group_ids = [ local.arvados_sg_id ]
62 iam_instance_profile = try(local.instance_profile[each.value], local.instance_profile.default).name
64 Name = "${local.cluster_name}_arvados_service_${each.value}"
68 volume_size = try(var.instance_volume_size[each.value], var.instance_volume_size.default)
71 # Sets IMDSv2 to required. Default is "optional".
72 http_tokens = "required"
76 # Avoids recreating the instance when the latest AMI changes.
77 # Use 'terraform taint' or 'terraform apply -replace' to force
84 resource "aws_iam_policy" "compute_node_ebs_autoscaler" {
85 name = "${local.cluster_name}_compute_node_ebs_autoscaler"
87 Version: "2012-10-17",
88 Id: "compute-node EBS Autoscaler policy",
93 "ec2:DescribeVolumeStatus",
94 "ec2:DescribeVolumes",
96 "ec2:ModifyInstanceAttribute",
97 "ec2:DescribeVolumeAttribute",
107 resource "aws_iam_policy_attachment" "compute_node_ebs_autoscaler_attachment" {
108 name = "${local.cluster_name}_compute_node_ebs_autoscaler_attachment"
109 roles = [ local.compute_node_iam_role_name ]
110 policy_arn = aws_iam_policy.compute_node_ebs_autoscaler.arn
113 resource "aws_iam_policy" "cloud_dispatcher_ec2_access" {
114 name = "${local.cluster_name}_cloud_dispatcher_ec2_access"
115 policy = jsonencode({
116 Version: "2012-10-17",
117 Id: "arvados-dispatch-cloud policy",
121 "ec2:DescribeKeyPairs",
124 "ec2:DescribeInstances",
126 "ec2:TerminateInstances"
135 Resource: "arn:aws:iam::*:role/${aws_iam_instance_profile.compute_node_instance_profile.name}"
140 resource "aws_iam_role" "cloud_dispatcher_iam_role" {
141 name = "${local.cluster_name}-dispatcher-00-iam-role"
142 assume_role_policy = "${file("../assumerolepolicy.json")}"
145 resource "aws_iam_policy_attachment" "cloud_dispatcher_ec2_access_attachment" {
146 name = "${local.cluster_name}_cloud_dispatcher_ec2_access_attachment"
147 roles = [ aws_iam_role.cloud_dispatcher_iam_role.name ]
148 policy_arn = aws_iam_policy.cloud_dispatcher_ec2_access.arn
151 resource "aws_eip_association" "eip_assoc" {
152 for_each = local.private_only ? [] : toset(local.public_hosts)
153 instance_id = aws_instance.arvados_service[each.value].id
154 allocation_id = local.eip_id[each.value]
157 resource "aws_iam_role" "default_iam_role" {
158 name = "${local.cluster_name}-default-iam-role"
159 assume_role_policy = "${file("../assumerolepolicy.json")}"
162 resource "aws_iam_policy" "ssl_privkey_password_access" {
163 name = "${local.cluster_name}_ssl_privkey_password_access"
164 policy = jsonencode({
165 Version: "2012-10-17",
168 Action: "secretsmanager:GetSecretValue",
169 Resource: "${aws_secretsmanager_secret.ssl_password_secret.arn}"
174 # Every service node needs access to the SSL privkey password secret for
175 # nginx to be able to use it.
176 resource "aws_iam_policy_attachment" "ssl_privkey_password_access_attachment" {
177 name = "${local.cluster_name}_ssl_privkey_password_access_attachment"
179 aws_iam_role.cloud_dispatcher_iam_role.name,
180 aws_iam_role.default_iam_role.name,
181 local.keepstore_iam_role_name,
183 policy_arn = aws_iam_policy.ssl_privkey_password_access.arn