Skip to content

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

License

Notifications You must be signed in to change notification settings

DanielRDias/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, mac2.metal)

Usage

module "dedicated-host" {
  source            = "DanielRDias/dedicated-host/aws"
  version           = "1.0.0"
  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           = "1.0.0"
  instance_type     = "mac1.metal"
  availability_zone = "us-east-1c"

  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-12.*"]
  }

  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. Therefore, if terraform fails, check if AWS has availability in another availability zone.

Examples

Terraform Docs

Requirements

No requirements.

Providers

Name Version
aws n/a

Modules

No modules.

Resources

Name Type
aws_ec2_host.this resource

Inputs

Name Description Type Default Required
auto_placement (Optional) 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. Valid values: on, off. Default: on. string "on" no
availability_zone The Availability Zone in which to allocate the Dedicated Host. string n/a yes
host_recovery (Optional) Indicates whether to enable or disable host recovery for the Dedicated Host. Host recovery is disabled by default. string "off" no
instance_family (Optional) Specifies the instance family to be supported by the Dedicated Hosts. If you specify an instance family, the Dedicated Hosts support multiple instance types within that instance family. Exactly one of instance_family or instance_type must be specified. string "undefined" no
instance_type (Optional) 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. Exactly one of instance_family or instance_type must be specified. string "undefined" no
outpost_arn (Optional) The Amazon Resource Name (ARN) of the AWS Outpost on which to allocate the Dedicated Host. string null no
tags (Optional) A list of tags to associate with the CloudFormation stack. Does not propagate to the Dedicated Host. map(string) null no

Outputs

Name Description
dedicated_host_id Dedicated Host ID
dedicated_hosts_arn The ARN of the Dedicated Host.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages