1

I am currently getting into Terraform and I am trying to structure the different resources that I am deploying by using tags and resource groups.

https://docs.aws.amazon.com/cli/latest/reference/resource-groups/index.html

I can easily add tags with Terraform and I can create the resource-group via aws cli but I really want to be able to do both with Terraform if possible.

The official Terraform docs currently seem to not support an aws_resource_group resource(I was able to find aws_inspector_resource_group and aws_iam_resource_group, which are different types of grouping resources) but I was wondering if anyone was able to achieve it via some kind of a workaround.

I would really appreciate any feedback on the matter.

Thanks in advance!

  • 1
    It's being worked on in https://github.com/terraform-providers/terraform-provider-aws/pull/6217. You might want to subscribe to that PR to see when the author gets a chance to fix up feedback on the PR and when it gets merged. – ydaetskcoR Dec 18 '18 at 15:57

2 Answers2

0

This has been released in aws provider 1.55.0: https://www.terraform.io/docs/providers/aws/r/resourcegroups_group.html

0

For anyone looking for a code example, try this:

resource "aws_resourcegroups_group" "code-resource" {
name = "code-resource"

  resource_query {
    query = <<JSON
{
  "ResourceTypeFilters": [
    "AWS::EC2::Instance"
  ],
  "TagFilters": [
    {
      "Key": "Stage",
      "Values": ["dev"]
    }
  ]
}
JSON
  }
}

Please update it to your liking and needs. also be sure to checkout the source documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/resourcegroups_group