github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/e2e/terraform/compute.tf (about)

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