|
| 1 | +variable "resource_name" { |
| 2 | + type = string |
| 3 | + default = "turbot-test-20200125-create-update-fleet" |
| 4 | + description = "Name of the resource used throughout the test." |
| 5 | +} |
| 6 | + |
| 7 | +variable "aws_profile" { |
| 8 | + type = string |
| 9 | + default = "default" |
| 10 | + description = "AWS credentials profile used for the test. Default is to use the default profile." |
| 11 | +} |
| 12 | + |
| 13 | +variable "aws_region" { |
| 14 | + type = string |
| 15 | + default = "us-east-1" |
| 16 | + description = "AWS region used for the test. Does not work with default region in config, so must be defined here." |
| 17 | +} |
| 18 | + |
| 19 | +variable "aws_region_alternate" { |
| 20 | + type = string |
| 21 | + default = "us-east-2" |
| 22 | + description = "Alternate AWS region used for tests that require two regions (e.g. DynamoDB global tables)." |
| 23 | +} |
| 24 | + |
| 25 | +provider "aws" { |
| 26 | + profile = var.aws_profile |
| 27 | + region = var.aws_region |
| 28 | +} |
| 29 | + |
| 30 | +provider "aws" { |
| 31 | + alias = "alternate" |
| 32 | + profile = var.aws_profile |
| 33 | + region = var.aws_region_alternate |
| 34 | +} |
| 35 | + |
| 36 | +data "aws_partition" "current" {} |
| 37 | +data "aws_caller_identity" "current" {} |
| 38 | +data "aws_region" "primary" {} |
| 39 | +data "aws_region" "alternate" { |
| 40 | + provider = aws.alternate |
| 41 | +} |
| 42 | + |
| 43 | +data "null_data_source" "resource" { |
| 44 | + inputs = { |
| 45 | + scope = "arn:${data.aws_partition.current.partition}:::${data.aws_caller_identity.current.account_id}" |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +data "aws_ami" "ubuntu" { |
| 50 | + most_recent = true |
| 51 | + filter { |
| 52 | + name = "name" |
| 53 | + values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] |
| 54 | + } |
| 55 | + filter { |
| 56 | + name = "virtualization-type" |
| 57 | + values = ["hvm"] |
| 58 | + } |
| 59 | + owners = ["099720109477"] |
| 60 | +} |
| 61 | + |
| 62 | +resource "aws_launch_template" "named_test_resource" { |
| 63 | + name = var.resource_name |
| 64 | + image_id = data.aws_ami.ubuntu.id |
| 65 | + instance_type = "t3.micro" |
| 66 | + |
| 67 | + tags = { |
| 68 | + Name = var.resource_name |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +resource "aws_ec2_fleet" "named_test_resource" { |
| 73 | + launch_template_config { |
| 74 | + launch_template_specification { |
| 75 | + launch_template_id = aws_launch_template.named_test_resource.id |
| 76 | + version = aws_launch_template.named_test_resource.latest_version |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + target_capacity_specification { |
| 81 | + default_target_capacity_type = "spot" |
| 82 | + total_target_capacity = 1 |
| 83 | + } |
| 84 | + |
| 85 | + type = "maintain" |
| 86 | + |
| 87 | + excess_capacity_termination_policy = "termination" |
| 88 | + |
| 89 | + replace_unhealthy_instances = false |
| 90 | + |
| 91 | + tags = { |
| 92 | + Name = var.resource_name |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +output "resource_aka" { |
| 97 | + value = aws_ec2_fleet.named_test_resource.arn |
| 98 | +} |
| 99 | + |
| 100 | +output "resource_id" { |
| 101 | + value = aws_ec2_fleet.named_test_resource.id |
| 102 | +} |
| 103 | + |
| 104 | +output "resource_name" { |
| 105 | + value = var.resource_name |
| 106 | +} |
| 107 | + |
| 108 | +output "aws_partition" { |
| 109 | + value = data.aws_partition.current.partition |
| 110 | +} |
| 111 | + |
| 112 | +output "account_id" { |
| 113 | + value = data.aws_caller_identity.current.account_id |
| 114 | +} |
| 115 | + |
| 116 | +output "launch_template_id" { |
| 117 | + value = aws_launch_template.named_test_resource.id |
| 118 | +} |
0 commit comments