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

Tag Feature: Difficulty with a count variable #53

Closed
dginther opened this issue Jan 12, 2019 · 4 comments
Closed

Tag Feature: Difficulty with a count variable #53

dginther opened this issue Jan 12, 2019 · 4 comments
Labels

Comments

@dginther
Copy link

Having an issue here:

Feature: Resources should be properly tagged
  In order to keep track of resource ownership
  As engineers
  We'll enforce tagging on all resources

  Scenario Outline: Name tag
    Given I have resource that supports tags defined
    Then it must contain tags
    And it must contain <tags>

  Examples:
  | tags        |
  | Name        |

result:

terraform-compliance v0.4.11 initiated
Steps    : /usr/local/lib/python2.7/site-packages/terraform_compliance/steps
Features : /Users/demianginther/git/tf-modules/compliance
TF Files : /var/folders/zf/f1h382nn35z3gd1kv92bw6r80000gn/T/tmpxTN1V9 (.)
Reading terraform files.
All HCL files look good.
Running tests.
Feature: Resources should be properly tagged  # /Users/demianginther/git/tf-modules/compliance/tags.feature
    In order to keep track of resource ownership
    As engineers
    We'll enforce tagging on all resources
1 features (0 passed)
1 scenarios (0 passed)
3 steps (0 passed)
Run 1547251063 finished within a moment
Error: Hook 'load_terraform_data' from /usr/local/lib/python2.7/site-packages/terraform_compliance/steps/terrain.py:6 raised: 'SyntaxError: invalid syntax (<string>, line 1)'

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/radish/hookregistry.py", line 121, in call
    func(model, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/terraform_compliance/steps/terrain.py", line 12, in load_terraform_data
    enable_resource_mounting(tf_conf.terraform_config)
  File "/usr/local/lib/python2.7/site-packages/terraform_compliance/extensions/terraform_validate.py", line 29, in enable_resource_mounting
    enable_resource_mounting(tf_conf, sub_value, sub_resource)
  File "/usr/local/lib/python2.7/site-packages/terraform_compliance/extensions/terraform_validate.py", line 29, in enable_resource_mounting
    enable_resource_mounting(tf_conf, sub_value, sub_resource)
  File "/usr/local/lib/python2.7/site-packages/terraform_compliance/extensions/terraform_validate.py", line 37, in enable_resource_mounting
    change_value_in_dict(tf_conf, target, {source: processing_resource})
  File "/usr/local/lib/python2.7/site-packages/terraform_compliance/common/helper.py", line 119, in change_value_in_dict
    target = eval('target_dictionary{}'.format(path_to_adjust))
  File "<string>", line 1
    target_dictionary["resource"]["!var"]["alb_enabled && !var"]["double_elb_listener_enabled && var"]["env == "prod" ? 1 : 0"]
                                                                                                                   ^
SyntaxError: invalid syntax

Relevant Terraform code:

resource "aws_cloudwatch_metric_alarm" "elb_single_listener_unhealthy_host_count" {
  alarm_name          = "${var.app_group}-${var.app}-${var.env}-unhealthy-host-count"
  count               = "${!var.alb_enabled && !var.double_elb_listener_enabled && var.env != "prod" ? 1 : 0}"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = "1"
  metric_name         = "UnHealthyHostCount"
  namespace           = "AWS/ELB"
  period              = "60"
  statistic           = "Maximum"
  threshold           = "${var.unhealthy_host_count_threshold}"

  dimensions {
    LoadBalancerName = "${aws_elb.app_elb_single_listener.name}"
  }

  alarm_description = "${aws_elb.app_elb_single_listener.name} - unhealthy host alarm triggered"

  alarm_actions = ["${var.slack_sns_topic}"]
}

Any ideas?

@eerkunt
Copy link
Member

eerkunt commented Jan 12, 2019

Hello,

The problem is usage of !var.. I haven't seen this before, which terraform version are you using ?

@eerkunt
Copy link
Member

eerkunt commented Jan 12, 2019

Yep just realised it was in a condition block, too early :)

Fixing the problem.

@eerkunt eerkunt added bug fixing A fix is addressed, no further data is required labels Jan 12, 2019
@eerkunt eerkunt mentioned this issue Jan 12, 2019
@eerkunt eerkunt removed the fixing A fix is addressed, no further data is required label Jan 12, 2019
@eerkunt eerkunt added this to the 0.4.12 milestone Jan 12, 2019
@eerkunt
Copy link
Member

eerkunt commented Jan 12, 2019

Hello @dginther,

First of all, thanks for reporting the problem! ( and also for the PR :) )

Could you please try this specific issue with version 0.4.12 ? It must be in all repos (docker, pypi, etc. ) in few minutes.

Thanks!

@dginther
Copy link
Author

Fixed in 0.4.13! Thanks!

@eerkunt eerkunt closed this as completed Jan 14, 2019
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