github.com/hernad/nomad@v1.6.112/e2e/terraform/compute.tf (about)

     1  # Copyright (c) HashiCorp, Inc.
     2  # SPDX-License-Identifier: MPL-2.0
     3  
     4  locals {
     5    ami_prefix = "nomad-e2e-v3"
     6  }
     7  
     8  resource "aws_instance" "server" {
     9    ami                    = data.aws_ami.ubuntu_jammy_amd64.image_id
    10    instance_type          = var.instance_type
    11    key_name               = module.keys.key_name
    12    vpc_security_group_ids = [aws_security_group.servers.id] # see also the secondary ENI
    13    count                  = var.server_count
    14    iam_instance_profile   = data.aws_iam_instance_profile.nomad_e2e_cluster.name
    15    availability_zone      = var.availability_zone
    16  
    17    # Instance tags
    18    tags = {
    19      Name           = "${local.random_name}-server-${count.index}"
    20      ConsulAutoJoin = "auto-join-${local.random_name}"
    21      User           = data.aws_caller_identity.current.arn
    22    }
    23  }
    24  
    25  resource "aws_instance" "client_ubuntu_jammy_amd64" {
    26    ami                    = data.aws_ami.ubuntu_jammy_amd64.image_id
    27    instance_type          = var.instance_type
    28    key_name               = module.keys.key_name
    29    vpc_security_group_ids = [aws_security_group.clients.id] # see also the secondary ENI
    30    count                  = var.client_count_ubuntu_jammy_amd64
    31    iam_instance_profile   = data.aws_iam_instance_profile.nomad_e2e_cluster.name
    32    availability_zone      = var.availability_zone
    33  
    34    # Instance tags
    35    tags = {
    36      Name           = "${local.random_name}-client-ubuntu-jammy-amd64-${count.index}"
    37      ConsulAutoJoin = "auto-join-${local.random_name}"
    38      User           = data.aws_caller_identity.current.arn
    39    }
    40  }
    41  
    42  resource "aws_instance" "client_windows_2016_amd64" {
    43    ami                    = data.aws_ami.windows_2016_amd64.image_id
    44    instance_type          = var.instance_type
    45    key_name               = module.keys.key_name
    46    vpc_security_group_ids = [aws_security_group.clients.id]
    47    count                  = var.client_count_windows_2016_amd64
    48    iam_instance_profile   = data.aws_iam_instance_profile.nomad_e2e_cluster.name
    49    availability_zone      = var.availability_zone
    50  
    51    user_data = file("${path.root}/userdata/windows-2016.ps1")
    52  
    53    # Instance tags
    54    tags = {
    55      Name           = "${local.random_name}-client-windows-2016-${count.index}"
    56      ConsulAutoJoin = "auto-join-${local.random_name}"
    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_jammy_amd64" {
    71    most_recent = true
    72    owners      = ["self"]
    73  
    74    filter {
    75      name   = "name"
    76      values = ["${local.ami_prefix}-ubuntu-jammy-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  }