Introduction
This article explains how to use multiple filter expressions when configuring the Host Catalogs AWS plugin in HCP Boundary, with a focus on how to apply tag-based filtering to select instances. Understanding how to use AND and OR-like logic with tag filters can help you efficiently organize and manage your AWS resources.
Pre-requisites
Before you begin, ensure that the following prerequisites are met:
- HCP Boundary Account: You should have an active HCP Boundary account.
- AWS Plugin Integration: You must have already set up the AWS plugin within HCP Boundary.
- AWS Host Catalog: You need to create an AWS plugin-type host catalog in HCP Boundary. For detailed instructions, refer to the Set Up Cloud Hosts in AWS tutorial.
1. Multiple Tag Filters (AND Operations)
When you apply multiple tag filters in the AWS plugin, AND operations are applied. This means all conditions must be met for an instance to be included in the host set.
-
Filter 1:
tag:Name=appvm
-
Filter 2:
tag-value=prod,abc
In this scenario, the result will include instances that meet both conditions:
- The instance must have the
Name
tag set toappvm
. - The instance must have a
tag-value
of eitherprod
orabc
.
Both conditions must be true for an instance to appear in the host set. This demonstrates that AND operations work between filters.
2. Using Multiple Tag Keys and Values
- Multiple Tag Keys:
If you want to select instances based on several tag keys, you can specify them in a comma-separated list.
Example:
tag-key=env,app,service-type
This filter will match instances that have any of the listed tag keys (either env
, app
, or service-type
).
- Multiple Tag Values:
Similarly, if you want to filter by multiple tag values, you can specify them in a comma-separated list as well.
Example:
tag-value=prod,staging
This filter will match instances where the tag value is either prod
or staging
.
Note : Currently, OR logic (i.e., selecting instances based on one of multiple conditions) is not directly supported within a single hostset filter. However, you can simulate OR logic by creating multiple hostsets, each with different filters.
Example:
- One hostset for the condition
tag-key=env
. - Another hostset for the condition
tag-value=prod
.
By using multiple hostsets with different tag filters, you can achieve the desired behavior of filtering based on either one of the conditions (OR logic).
Additional Resources: