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

Count giving unexpected and unclear number #242

Closed
Verhaeg opened this issue Mar 27, 2020 · 7 comments
Closed

Count giving unexpected and unclear number #242

Verhaeg opened this issue Mar 27, 2020 · 7 comments
Assignees
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation

Comments

@Verhaeg
Copy link

Verhaeg commented Mar 27, 2020

Description :
Trying to write a simple count of resources created but the expected value is 615 instead of 18.

Using terraform-gsuite plugin to manage new groups and using a module to create those groups with certain people already in them. Expected to assert that all groups I created are present in the plan using the count check but the tests fail with unrealistic count.

To Reproduce

  1. <Either a sample terraform code, or your terraform plan file if it doesn't have any confidential information>
provider gsuite {
    oauth_scopes = [
        "https://www.googleapis.com/auth/admin.directory.group",
        "https://www.googleapis.com/auth/admin.directory.user"
    ]
}

resource "gsuite_group" "my-group-i" {
  email       = "[email protected]"
  name        = "My Group I"
}

resource "gsuite_group" "my-group-ii" {
  email       = "[email protected]"
  name        = "My Group II"
}
  1. terraform-compliance -p .plan.out --features .tests/compliance
  2. python package
  3. Failure: for ['module.my_team.gsuite_group.level-i', 'module.my_team.gsuite_group.level-ii', 'module.my_team.gsuite_group.level-iii', ...] on email. 615 is not equal to 18.
Scenario: Ensure I have all groups
    Given I have gsuite_group defined
    When it contains email
    And I count them
    Then its value must be equal to 2

Expected behavior :
Test should pass

Tested versions :

  • terraform-compliance v1.1.12
  • Terraform v0.12.24
  • Python 2.7.17

Additional context
The examples I gave (the codes) are reduced since we have some internal names for this case. But should suffice.
Also, I'm currently unaware of all existing groups we have, but those are the only managed ones

@eerkunt
Copy link
Member

eerkunt commented Mar 30, 2020

Hi @Verhaeg,

It is hard to understand since this looks like a custom provider. Would it be possible post a plan.out (or plan.out.json) for debugging ?

@eerkunt eerkunt added the require more data Further data is required to initiate debugging/troubleshooting label Mar 30, 2020
@Verhaeg
Copy link
Author

Verhaeg commented Mar 30, 2020

I had to comment out the members (not important right now) and changed the names by leaving only 3 groups created.

plan.out.txt

Sorry for not being able to leave as an example, but here is the test output for this file:

Feature: Email groups should be created with three levels and users inside

Scenario: Ensure I have all groups
    Given I have gsuite_group defined
    When it contains email
    And I count them
    Then its value must be equal to 3
$ terraform-compliance -p ./plan.out.txt --features tests/compliance
terraform-compliance v1.1.12 initiated

🚩 Features	: /Users/verhaeg/Projects/terraform-gsuit/tests/compliance
🚩 Plan File	: /Users/verhaeg/Projects/terraform-gsuit/plan.out.txt

🚩 Running tests. 🎉

Feature: Email groups should be created with three levels and users inside  # /Users/verhaeg/Projects/terraform-gsuit/tests/compliance/groups.feature

    Scenario: Ensure I have all groups
        Given I have gsuite_group defined
        When it contains email
        And I count them
			Failure: for ['module.team_myteam.gsuite_group.gcp-level-i', 'module.team_myteam.gsuite_group.gcp-level-ii', 'module.team_myteam.gsuite_group.gcp-level-iii'] on email. 81 is not equal to 3.
        Then its value must be equal to 3
          Failure:

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

@eerkunt
Copy link
Member

eerkunt commented Mar 30, 2020

Yep, reproduced the problem with your plan output, thank you!

Having a deeper look.

@eerkunt
Copy link
Member

eerkunt commented Mar 30, 2020

Yep, found the problem. It looks like there is slight problem on the count function where we count the characters within those emails :)

Testing my fix.

@eerkunt eerkunt added waiting for confirmation Workaround/Fix applied, waiting for confirmation and removed require more data Further data is required to initiate debugging/troubleshooting labels Mar 30, 2020
@eerkunt
Copy link
Member

eerkunt commented Mar 30, 2020

Just released 1.1.14, will take few minutes to get into PyPi.

Could you please try and let me know about the result ? Thanks!

@Verhaeg
Copy link
Author

Verhaeg commented Mar 30, 2020

Awesome! Tests passed now!

thanks for the quick fix

@Verhaeg Verhaeg closed this as completed Mar 30, 2020
@ghost
Copy link

ghost commented Mar 30, 2020

This issue's conversation is now locked. If you want to continue this discussion please open a new issue.

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants