github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/e2e/terraform/compute.tf (about)

     1  locals {
     2    ami_prefix = "nomad-e2e-v3"
     3  }
     4  
     5  resource "aws_instance" "server" {
     6    ami                    = data.aws_ami.ubuntu_jammy_amd64.image_id
     7    instance_type          = var.instance_type
     8    key_name               = module.keys.key_name
     9    vpc_security_group_ids = [aws_security_group.primary.id]
    10    count                  = var.server_count
    11    iam_instance_profile   = data.aws_iam_instance_profile.nomad_e2e_cluster.name
    12    availability_zone      = var.availability_zone
    13  
    14    # Instance tags
    15    tags = {
    16      Name           = "${local.random_name}-server-${count.index}"
    17      ConsulAutoJoin = "auto-join-${local.random_name}"
    18      User           = data.aws_caller_identity.current.arn
    19    }
    20  }
    21  
    22  resource "aws_instance" "client_ubuntu_jammy_amd64" {
    23    ami                    = data.aws_ami.ubuntu_jammy_amd64.image_id
    24    instance_type          = var.instance_type
    25    key_name               = module.keys.key_name
    26    vpc_security_group_ids = [aws_security_group.primary.id]
    27    count                  = var.client_count_ubuntu_jammy_amd64
    28    iam_instance_profile   = data.aws_iam_instance_profile.nomad_e2e_cluster.name
    29    availability_zone      = var.availability_zone
    30  
    31    # Instance tags
    32    tags = {
    33      Name           = "${local.random_name}-client-ubuntu-jammy-amd64-${count.index}"
    34      ConsulAutoJoin = "auto-join-${local.random_name}"
    35      User           = data.aws_caller_identity.current.arn
    36    }
    37  }
    38  
    39  resource "aws_instance" "client_windows_2016_amd64" {
    40    ami                    = data.aws_ami.windows_2016_amd64.image_id
    41    instance_type          = var.instance_type
    42    key_name               = module.keys.key_name
    43    vpc_security_group_ids = [aws_security_group.primary.id]
    44    count                  = var.client_count_windows_2016_amd64
    45    iam_instance_profile   = data.aws_iam_instance_profile.nomad_e2e_cluster.name
    46    availability_zone      = var.availability_zone
    47  
    48    user_data = file("${path.root}/userdata/windows-2016.ps1")
    49  
    50    # Instance tags
    51    tags = {
    52      Name           = "${local.random_name}-client-windows-2016-${count.index}"
    53      ConsulAutoJoin = "auto-join-${local.random_name}"
    54      User           = data.aws_caller_identity.current.arn
    55    }
    56  }
    57  
    58  data "external" "packer_sha" {
    59    program = ["/bin/sh", "-c", <<EOT
    60  sha=$(git log -n 1 --pretty=format:%H packer)
    61  echo "{\"sha\":\"$${sha}\"}"
    62  EOT
    63    ]
    64  
    65  }
    66  
    67  data "aws_ami" "ubuntu_jammy_amd64" {
    68    most_recent = true
    69    owners      = ["self"]
    70  
    71    filter {
    72      name   = "name"
    73      values = ["${local.ami_prefix}-ubuntu-jammy-amd64-*"]
    74    }
    75  
    76    filter {
    77      name   = "tag:OS"
    78      values = ["Ubuntu"]
    79    }
    80  
    81    filter {
    82      name   = "tag:BuilderSha"
    83      values = [data.external.packer_sha.result["sha"]]
    84    }
    85  }
    86  
    87  data "aws_ami" "windows_2016_amd64" {
    88    most_recent = true
    89    owners      = ["self"]
    90  
    91    filter {
    92      name   = "name"
    93      values = ["${local.ami_prefix}-windows-2016-amd64-*"]
    94    }
    95  
    96    filter {
    97      name   = "tag:OS"
    98      values = ["Windows2016"]
    99    }
   100  
   101    filter {
   102      name   = "tag:BuilderSha"
   103      values = [data.external.packer_sha.result["sha"]]
   104    }
   105  }