# Tags

Allows assertions on the tags associated with a synthesized CDK stack's manifest.

Stack tags are not part of the synthesized template, so can only be
checked from the manifest in this manner.

Obtainable from: Tags.fromStack

- Source: [`assertions/lib/tags.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/assertions/lib/tags.ts#L14)
- Type last changed: v2.137.0 · 11 Apr 2024

## Example

TypeScript:

```ts
const tags = Tags.fromStack(stack);

// using a default 'objectLike' Matcher
tags.hasValues({
  'tag-name': 'tag-value',
});

// ... with Matchers embedded
tags.hasValues({
  'tag-name': Match.stringLikeRegexp('value'),
});

// or another object Matcher at the top level
tags.hasValues(Match.objectEquals({
  'tag-name': Match.anyValue(),
}));
```

Python:

```python
tags = Tags.from_stack(stack)

# using a default 'objectLike' Matcher
tags.has_values({
    "tag-name": "tag-value"
})

# ... with Matchers embedded
tags.has_values({
    "tag-name": Match.string_like_regexp("value")
})

# or another object Matcher at the top level
tags.has_values(Match.object_equals({
    "tag-name": Match.any_value()
}))
```

Java:

```java
Tags tags = Tags.fromStack(stack);

// using a default 'objectLike' Matcher
tags.hasValues(Map.of(
        "tag-name", "tag-value"));

// ... with Matchers embedded
tags.hasValues(Map.of(
        "tag-name", Match.stringLikeRegexp("value")));

// or another object Matcher at the top level
tags.hasValues(Match.objectEquals(Map.of(
        "tag-name", Match.anyValue())));
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var tags = Tags.FromStack(stack);

// using a default 'objectLike' Matcher
tags.HasValues(new Dictionary<string, string> {
    { "tag-name", "tag-value" }
});

// ... with Matchers embedded
tags.HasValues(new Dictionary<string, Matcher> {
    { "tag-name", Match.StringLikeRegexp("value") }
});

// or another object Matcher at the top level
tags.HasValues(Match.ObjectEquals(new Dictionary<string, object> {
    { "tag-name", Match.AnyValue() }
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
tags := awscdk.Tags_FromStack(stack)

// using a default 'objectLike' Matcher
tags.HasValues(map[string]*string{
	"tag-name": jsii.String("tag-value"),
})

// ... with Matchers embedded
tags.HasValues(map[string]Matcher{
	"tag-name": awscdk.Match_stringLikeRegexp(jsii.String("value")),
})

// or another object Matcher at the top level
tags.HasValues(awscdk.Match_ObjectEquals(map[string]interface{}{
	"tag-name": awscdk.Match_anyValue(),
}))
```

## Methods

- `all(): { [key: string]: string }` — Get the tags associated with the manifest.

  This will be an empty object if
  no tags were supplied.

  **Returns:** The tags associated with the stack's synthesized manifest.

- `fromStack(stack: Stack): Tags // chainable` (static) — Find tags associated with a synthesized CDK `Stack`.

  **Parameters**

  - `stack` — the CDK Stack to find tags on.

- `hasNone(): void` — Assert that the there are no tags associated with the synthesized CDK Stack's manifest.

  This is a convenience method over `hasValues(Match.exact({}))`, and is
  present because the more obvious method of detecting no tags
  (`Match.absent()`) will not work. Manifests default the tag set to an empty
  object.

- `hasValues(tags: any): void` — Assert that the given Matcher or object matches the tags associated with the synthesized CDK Stack's manifest.

  **Parameters**

  - `tags` — the expected set of tags.
