Skip to content

Commit

Permalink
Feat: support terraform 1.3 (#157)
Browse files Browse the repository at this point in the history
Co-authored-by: Henry Buckle <[email protected]>
  • Loading branch information
hbuckle and Henry Buckle authored Oct 10, 2022
1 parent b45c746 commit 3b808ca
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
terraform_version: ['11','12','13','14','15','1.0','1.1','1.2']
terraform_version: ['11','12','13','14','15','1.0','1.1','1.2','1.3']

steps:
- name: Set up Go
Expand Down Expand Up @@ -131,4 +131,3 @@ jobs:
- name: Test
run: |
go test -v -run ^TestTerragruntWithCache$
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Maintaining tags across your application is hard, especially when done manually.

## How?
### Prerequisites
- Terraform 0.11 through 1.2
- Terraform 0.11 through 1.3

### Usage
1. Install from homebrew:
Expand All @@ -37,7 +37,7 @@ Maintaining tags across your application is hard, especially when done manually.
or
```bash
terratag -dir=foo/bar -tags="environment_id=prod,some-tag=value"
```
```

Terratag supports the following arguments:
- `-dir` - optional, the directory to recursively search for any `.tf` file and try to terratag it.
Expand Down Expand Up @@ -193,9 +193,9 @@ my_test
All commands will be executed wherever down the hierarchy where `main.tf` is located.
We do that to allow cases where complex nested submodule resolution may take place, and one would like to test how a directory higher up the hierarchy gets resolved.
- `expected` is a directory in which all `.terratag.tf` files will be matched with the output directory

Each terraform version has it's own config file containing the list of test suites to run.
The config file is under `test/fixtures/terraform_xx/config.yaml` where `xx` is the terraform version.
The config file is under `test/fixtures/terraform_xx/config.yaml` where `xx` is the terraform version.

#### What's being tested?
Each test will run:
Expand Down
4 changes: 2 additions & 2 deletions internal/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func GetTerraformVersion() (*common.Version, error) {
return nil, err
}

if (majorVersion == 0 && minorVersion < 11 || minorVersion > 15) || (majorVersion == 1 && minorVersion > 2) {
return nil, fmt.Errorf("terratag only supports Terraform from version 0.11.x and up to 1.2.x - your version says %s", outputAsString)
if (majorVersion == 0 && minorVersion < 11 || minorVersion > 15) || (majorVersion == 1 && minorVersion > 3) {
return nil, fmt.Errorf("terratag only supports Terraform from version 0.11.x and up to 1.3.x - your version says %s", outputAsString)
}

return &common.Version{Major: majorVersion, Minor: minorVersion}, nil
Expand Down
12 changes: 12 additions & 0 deletions terratag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ func TestTerraform1o2WithSkip(t *testing.T) {
testTerraformWithFilter(t, "15_1.2_skip", ".*", "azurerm_resource_group")
}

func TestTerraform1o3(t *testing.T) {
testTerraform(t, "15_1.3")
}

func TestTerraform1o3WithFilter(t *testing.T) {
testTerraformWithFilter(t, "15_1.3_filter", "azurerm_resource_group|aws_s3_bucket", "")
}

func TestTerraform1o3WithSkip(t *testing.T) {
testTerraformWithFilter(t, "15_1.3_skip", ".*", "azurerm_resource_group")
}

func TestTerragruntWithCache(t *testing.T) {
if _, skip := os.LookupEnv("SKIP_INTEGRATION_TESTS"); skip {
t.Skip("skipping integration test")
Expand Down
17 changes: 17 additions & 0 deletions test/fixture/terraform_15_1.3/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
suites:
- aws_autoscaling_group
- aws_submodule
- aws_tags_block
- aws_tags_map
- azurerm_api_management_named_value
- azurerm_kubernetes_cluster
- azurerm_tags_map
- azurestack_tags_map
- git_issue_17__tfschema_provider_not_from_prefix
- git_issue_43__invalid_tf_files_in_subfolders
- git_issue_56__line_ends_with_closing_paren
- git_issue_66_aws_aliased_provider
- git_issue_88__corrupt_hcl_file
- google_beta_resource_skip
- google_container_cluster
- google_labels_map
2 changes: 2 additions & 0 deletions test/fixture/terraform_15_1.3_filter/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
suites:
- aws_azure
2 changes: 2 additions & 0 deletions test/fixture/terraform_15_1.3_skip/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
suites:
- azurerm_skip
1 change: 1 addition & 0 deletions test/tfenvconf/terraform_1.3/.terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.3.0

0 comments on commit 3b808ca

Please sign in to comment.