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

Counting repeatable argument blocks #194

Closed
ajmahoney opened this issue Dec 20, 2019 · 4 comments
Closed

Counting repeatable argument blocks #194

ajmahoney opened this issue Dec 20, 2019 · 4 comments
Assignees
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation

Comments

@ajmahoney
Copy link

Description :
When adding an argument block that can be added multiple times (e.g. aws_instance.network_interface) to a resource only once, the count returned is the size of the first object not the size of the list. This makes it impossible to ensure there is only one (or the size of the map for the argument).
I first noticed this counting google_compute_firewall.allow but realise that this is probably more AWS focused so have put together enough to generate a plan without requiring credentials.

To Reproduce
1.

provider "aws" {
  region                      = "us-west-2"
  access_key                  = "my-access-key"
  secret_key                  = "my-secret-key"
  skip_credentials_validation = true
  skip_get_ec2_platforms      = true
  skip_region_validation      = true
  skip_requesting_account_id  = true
  version                     = "~> 2.43"
}

resource "aws_instance" "one" {
  ami           = "ami-6d1c2007"
  instance_type = "t2.micro"

  network_interface {
    device_index         = 1
    network_interface_id = "eth0"
  }
}

resource "aws_instance" "two" {
  ami           = "ami-6d1c2007"
  instance_type = "t2.micro"

  network_interface {
    device_index         = 1
    network_interface_id = "eth0"
  }

  network_interface {
    device_index         = 2
    network_interface_id = "eth1"
  }
}
  1. terraform-compliance -p plan.out -f ./
  2. Seems to happen in steps.py it_condition_contain_something
$ terraform-compliance -p plan.out -f ./
terraform-compliance local development version initiated

. Converting terraform plan file.
* Features  : /home/andy/src/terraform-compliance/bug
* Plan File : /home/andy/src/terraform-compliance/bug/plan.out.json

. Running tests.
Feature: Count bug  # /home/andy/src/terraform-compliance/bug/count.feature

    Scenario: Ensure one network is attached to one
        Given I have aws_instance defined
        When its name is one
        And it contains network_interface
        And I count them
        Then I expect the result is equal to 1
          Failure: for aws_instance.one on network_interface. 3 is not equal to 1.

    Scenario: Ensure two networks are attached to two
        Given I have aws_instance defined
        When its name is two
        And it contains network_interface
        And I count them
        Then I expect the result is equal to 2

1 features (0 passed, 1 failed)
2 scenarios (1 passed, 1 failed)
10 steps (9 passed, 1 failed)
Run 1576845649 finished within a moment
Feature: Count bug

    Scenario: Ensure one network is attached to one
    Given I have aws_instance defined
    When its name is one
    And it contains network_interface
    And I count them
    Then I expect the result is equal to 1

    Scenario: Ensure two networks are attached to two
    Given I have aws_instance defined
    When its name is two
    And it contains network_interface
    And I count them
    Then I expect the result is equal to 2

Expected behavior :

Tested versions :

  • terraform-compliance v1.0.58 initiated
  • Terraform v0.12.17
@eerkunt
Copy link
Member

eerkunt commented Dec 20, 2019

Thanks a lot for reporting it 🎉

Will have a look and clear all issues waiting on the Christmas break :)

@eerkunt eerkunt mentioned this issue Jan 6, 2020
18 tasks
@eerkunt
Copy link
Member

eerkunt commented Feb 1, 2020

Can you have a try the same functionality with 1.1.+ please ? 🎉

@eerkunt eerkunt added the waiting for confirmation Workaround/Fix applied, waiting for confirmation label Feb 1, 2020
@eerkunt
Copy link
Member

eerkunt commented Feb 16, 2020

Closing the issue due to inactivity. Please do not hesitate to open a new issue if the problem still persists.

Thanks!

@eerkunt eerkunt closed this as completed Feb 16, 2020
@ghost
Copy link

ghost commented Feb 16, 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 Feb 16, 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