You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The terraform-aws-ecr module enables several common architectures for container image management.
@@ -316,6 +319,37 @@ module "ecr" {
316
319
317
320
For detailed examples of all variables with explanations, see [docs/variable-examples.md](docs/variable-examples.md).
318
321
322
+
## Testing
323
+
324
+
This module uses [Terratest](https://github.com/gruntwork-io/terratest) for automated testing of the module functionality. The tests validate that the module can correctly:
This directory contains automated tests for the terraform-aws-ecr module. The tests use [Terratest](https://github.com/gruntwork-io/terratest), a Go library that provides utilities for testing Terraform code.
4
+
5
+
## Prerequisites
6
+
7
+
1.[Go](https://golang.org/) (version 1.16 or later)
8
+
2.[Terraform](https://www.terraform.io/) (version 1.3.0 or later)
9
+
3. AWS credentials configured (via environment variables, shared credentials file, or AWS IAM role)
10
+
11
+
## Running the Tests
12
+
13
+
To run all tests:
14
+
15
+
```bash
16
+
cdtest
17
+
go test -v
18
+
```
19
+
20
+
To run a specific test:
21
+
22
+
```bash
23
+
cdtest
24
+
go test -v -run TestEcrBasicCreation
25
+
```
26
+
27
+
## Test Structure
28
+
29
+
The test suite includes the following tests:
30
+
31
+
1.**Basic Repository Test**: Tests the creation of a simple ECR repository with minimal configuration.
32
+
- Verifies repository creation
33
+
- Checks image tag mutability
34
+
- Validates repository URL and ARN
35
+
36
+
2.**Complete Repository Test**: Tests the creation of a fully configured ECR repository.
37
+
- Verifies repository creation with all features
38
+
- Validates repository policies
39
+
- Checks lifecycle policies
40
+
- Tests KMS encryption
41
+
42
+
## Test Fixtures
43
+
44
+
The test fixtures are located in the `fixtures` directory:
45
+
46
+
-`fixtures/basic`: A simple ECR repository configuration
47
+
-`fixtures/complete`: A full-featured ECR repository configuration with policies and KMS encryption
48
+
49
+
## AWS Resources
50
+
51
+
These tests create real AWS resources, which might incur costs. The tests use the `force_delete = true` option to ensure that repositories can be cleaned up even if they contain images.
52
+
53
+
All resources are tagged with `Test = "true"` for identification and are destroyed after the test completes. However, if a test fails, you may need to manually delete the resources.
54
+
55
+
## CI/CD Integration
56
+
57
+
These tests can be run in GitHub Actions using the workflow defined in `.github/workflows/test.yml`.
0 commit comments