Skip to content

Terraform module which creates EC2 dedicated host on AWS. Required for macOS instances (mac1.metal)

License

Notifications You must be signed in to change notification settings

bag0bits/terraform-aws-dedicated-host

 
 

Repository files navigation

Terraform AWS Dedicated Host Module

Terraform module which creates EC2 dedicated host on AWS. Required for macOS instances (mac1.metal)

Usage

module "dedicated-host" {
  source            = "DanielRDias/dedicated-host/aws"
  version           = "0.2.1"
  instance_type     = "c5.large"
  availability_zone = "us-east-1a"

  tags = {
    Name = "Terraform Mac"
  }
}

Full example for mac1.metal

provider "aws" {
  region = "us-east-1"
}

module "dedicated-host" {
  source            = "DanielRDias/dedicated-host/aws"
  version           = "0.2.1"
  instance_type     = "mac1.metal"
  availability_zone = "us-east-1a"

  tags = {
    Name = "Terraform Mac"
  }
}

resource "aws_ec2_tag" "mac" {
  resource_id = module.dedicated-host.dedicated_hosts["HostID"]
  key         = "Name"
  value       = "Terraform Mac"
}

resource "aws_instance" "mac" {
  ami           = data.aws_ami.mac.id
  instance_type = "mac1.metal"
  host_id       = module.dedicated-host.dedicated_hosts["HostID"]
  subnet_id     = "subnet-xxxx" # Subnet ID in the same AZ as the dedicated host

  tags = {
    Name = "Terraform Mac"
  }
}

data "aws_ami" "mac" {
  most_recent = true

  filter {
    name   = "name"
    values = ["amzn-ec2-macos-10.15*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["amazon"]
}

output "mac_ami" {
  value = data.aws_ami.mac.id
}

output "dedicated-host" {
  value = module.dedicated-host.dedicated_hosts["HostID"]
}

Note: AWS has a limited capacity for dedicated hosts. If terraform times out and fails to create the dedicated host, the cloudformation stack will stay in your account until you do terraform destroy. Check https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-stack-stuck-progress/ for more details.

Examples

Terraform Docs

Requirements

No requirements.

Providers

Name Version
aws n/a

Inputs

Name Description Type Default Required
auto_placement Indicates whether the host accepts any untargeted instance launches that match its instance type configuration, or if it only accepts Host tenancy instance launches that specify its unique host ID. string "on" no
availability_zone The Availability Zone in which to allocate the Dedicated Host. string n/a yes
cf_stack_name Dedicated host CloudFormation stack name. It can include letters (A-Z and a-z), numbers (0-9), and dashes (-). string "dedicated-hosts-stack" no
host_recovery Indicates whether to enable or disable host recovery for the Dedicated Host. Host recovery is disabled by default. string "off" no
instance_type Specifies the instance type to be supported by the Dedicated Hosts. If you specify an instance type, the Dedicated Hosts support instances of the specified instance type only. string n/a yes
tags A list of tags to associate with the CloudFormation stack. Does not propagate to the Dedicated Host. map(string) n/a no

Outputs

Name Description
cf_stack_id Cloud Formation Stack ID
dedicated_host_id Dedicated Host ID
dedicated_hosts Maps with the dedicated hosts IDs

About

Terraform module which creates EC2 dedicated host on AWS. Required for macOS instances (mac1.metal)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 100.0%