Open sc250024 opened 2 years ago
To anyone who reads a bit further, I checked into this, and from what I can tell, I think that the AWS API doesn't allow you to create this resource (host resource groups) directly. What's even more confusing is that AWS treats host resource groups and regular resource groups as sort of the same.
Here's an image showing this:
Basically, host resource groups are treated as regular resource groups, but not the other way around.
This means that there are two places inside of the console to create resources that are almost the same. They both use the same ARN format. But if you try to pass in a regular resource group (on the right) to a launch template, it will fail.
This seems like an error in the way AWS is handling this type of resource.
Hi @sc250024,
I know this is like a year too late but I was looking at doing the same thing and the AWS provider does actually allow for this. It's created just like a RG but instead of using a resource group query, you use a service configuration.
So for instance, to set up the DRG for AWS Licence Manager, you use the configuration parameters you can find here: https://docs.aws.amazon.com/ARG/latest/userguide/about-slg.html#about-slg-types-resourcegroups-ec2-hostmanagement
There's a AWS blog that links to a repo with examples. https://aws.amazon.com/blogs/compute/implementing-autoscaling-for-ec2-mac-instances https://github.com/aws-samples/amazon-autoscaling-mac1metal-ec2-with-terraform
The TF would look like this:
resource "aws_licensemanager_license_configuration" "license_config"{
name = "MyRequiredLicense"
description = "Pass through configuration for Host Resource Group"
license_count = 32
license_count_hard_limit = false
license_counting_type = "Core"
}
resource "aws_resourcegroups_group" "aws_resourcegroups_licence_group" {
name = "LicenceManagerResourceGroup"
configuration {
type = "AWS::EC2::HostManagement"
parameters {
name = "allowed-host-based-license-configurations"
values = [aws_licensemanager_license_configuration.license_config.arn]
}
parameters {
name = "auto-allocate-host"
values = [true]
}
parameters {
name = "auto-release-host"
values = [true]
}
parameters {
name = "auto-host-recovery"
values = [true]
}
parameters {
name = "allowed-host-families"
values = ["mac2"]
}
}
configuration {
type = "AWS::ResourceGroups::Generic"
parameters {
name = "allowed-resource-types"
values = ["AWS::EC2::Host"]
}
parameters {
name = "deletion-protection"
values = ["UNLESS_EMPTY"]
}
}
}
Hope this helps someone.
Edit: It looks like you don't need to use the license config, so instead of this:
parameters {
name = "allowed-host-based-license-configurations"
values = [aws_licensemanager_license_configuration.license_config.arn]
}
you can instead just use:
parameters {
name = "any-host-based-license-configuration"
values = [true]
}
Community Note
Description
As best I can tell, while there is currently support for Resource Groups (via the aws_resourcegroups_group resource), there is no support for the (annoyingly very similarly named) host resource group which is located within the AWS License Manager scope.
This is a screenshot of that resource:
I discovered the lack of this resource while trying to configure an autoscaling group comprised of
metal
type instances, and realized that there is a fairly lengthy process to go through on the licensing interface in order to configure this. I mistakenly thought that passing in the ARN of a aws_resourcegroups_group into theaws_launch_template
was what was needed, but this is not the case.The initial desire for this ticket was to do something like the following article: https://devdosvid.blog/2021/10/24/auto-scaling-group-for-your-macos-ec2-instances-fleet/. I noticed that this needed resource did not yet exist, so I figured I'd create an issue to create it.
Following the current resource naming conventions, this new resource would be aws_licensemanager_host_resource_group.
New or Affected Resource(s)
Potential Terraform Configuration
Based on the current way to configure this resource via the console...
...the Terraform resource could probably be configured like so: