Updated on the 23rd of October, 2021: Terraform AWS provider now supports Dedicated Hosts natively
In November 2021, AWS announced the support for Mac mini instances.
I believe this is huge, even despite the number of constraints this solution has. This offering opens the door to seamless macOS CI/CD integration into existing AWS infrastructure.
So here is a quick-start example of creating the dedicated host and the instance altogether using Terraform.
I intentionally used some hardcoded values for the sake of simplicity in the example.
resource "aws_ec2_host" "example_host" {
instance_type = "mac1.metal"
availability_zone = "us-east-1a"
}
resource "aws_instance" "example_instance" {
ami = data.aws_ami.mac1metal.id
host_id = aws_ec2_host.example_host.id
instance_type = "mac1.metal"
subnet_id = data.aws_subnet.example_subnet.id
}
data "aws_subnet" "example_subnet" {
availability_zone = "us-east-1a"
filter {
name = "tag:Tier" # you should omit this filter if you don't distinguish your subnets on private and public
values = ["private"]
}
}
data "aws_ami" "mac1metal" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = ["amzn-ec2-macos-11*"] # get latest BigSur AMI
}
}
Simple as that, yes. Now, you can integrate it into your CI system and have the Mac instance with the underlying host in a bundle.
π‘ Pro tip: you can leverage the aws_ec2_instance_type_offerings
Data Source and use its output with aws_subnet
source to avoid availability zone hardcoding.
To make the code more uniform and reusable, you can wrap it into a Terraform module that accepts specific parameters (such as instance_type
or availability_zone
) as input variables.
If you liked the article, please support me by sharing it on social networks π
Top comments (4)
This terraform module will use the same approach to solve the problem:
registry.terraform.io/modules/Dani...
Terraform AWS provider has a pull request to solve this problem open for more than 1 year :(
github.com/hashicorp/terraform-pro...
If you used this feature, please upvote the PR
Yeah, that issue already has my vote, as well as related PR. But still no luck :(
Hello Daniel,
Can we create multiple dedicated hosts and mac instances from your script
@kondetiram hi there! :) Check out the update to this article β Terraform now supports Dedicated Hosts natively. So you can create a module and define the
count
argument for it nice and easy now π€Some comments may only be visible to logged-in visitors. Sign in to view all comments.