Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version strings with minor versions ending in 0 are truncated #752

Open
nikki-quant opened this issue Jan 28, 2025 · 0 comments
Open

Version strings with minor versions ending in 0 are truncated #752

nikki-quant opened this issue Jan 28, 2025 · 0 comments
Assignees
Labels

Comments

@nikki-quant
Copy link

Dear Terraform Compliance team, thanks for making this useful tool!

Description

When writing tests which compare a version string with a major and minor part, Terraform Compliance appears to trim any trailing zeros from the minor part if it is a multiple of ten. For example, "1.30" is rounded to 1.3.

This means these tests will error even when the actual resource version matches the value provided in the test.

To Reproduce

Feature File:

Feature: Check the versions are correct

    Scenario: Example compliance test
        Given I have local_file resource configured
        When its name is foo
        Then it must have content
        And its value must be "1.30"

Plan File:

terraform {
  required_version = ">= 1.9.6"
}

terraform {
  required_providers {
    local = {
      source = "hashicorp/local"
      version = "2.5.2"
    }
  }
}

resource "local_file" "foo" {
  content  = "1.30"
  filename = "${path.module}/foo.bar"
}

Used terraform-compliance Parameters:

terraform-compliance -f features/ -p plan.json

Running via Docker:
Yes.

 % docker version
Client:
 Cloud integration: v1.0.35+desktop.4
 Version:           24.0.6
 API version:       1.43
 Go version:        go1.20.7
 Git commit:        ed223bc
 Built:             Mon Sep  4 12:28:49 2023
 OS/Arch:           darwin/amd64
 Context:           desktop-linux

Error Output:

% terraform-compliance -f features/ -p plan.json
terraform-compliance v1.3.49 initiated

🚩 Features     : /target/features/
🚩 Plan File    : /target/plan.json

🚩 Running tests. 🎉

Feature: Check the versions are correct  # /target/features/version.feature

    Scenario: Example compliance test
        Given I have local_file resource configured
        When its name is foo
        Then it must have content
                Failure: content property in local_file.foo resource does not match with ^1\.30$ case insensitive regex. It is set to 1.3.
        And its value must be "1.30"
          Failure: 

1 features (0 passed, 1 failed)
1 scenarios (0 passed, 1 failed)
4 steps (3 passed, 1 failed)
Run 1738057003 finished within a moment

Expected Behavior:

To be able to test that a Terraform resource which returns a version string matches an expected version.

Tested Versions:

  • terraform-compliance version: v1.3.49
  • terraform version: v1.9.6

Additional Context:

I originally came across this issue with AWS EKS cluster Kubernetes versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants