-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to enforce Resource2 is created when I have Resource1 defined? #292
Comments
I glossed over the documentation, and couldn't find a way to do that. I believe you are looking for something like
Since When directives only work within a "given" resource. Maybe those tests could be supported if we had one of the two:
@eerkunt any thoughts? |
I think with the use of Given I have any resource defined following a filtering step like ; When its type is <resource_type> and use of E.g. (haven't tried) ; Scenario: VPC is there
Given I have any resource defined
When its type is not aws_vpc
Then it must fail
@precondition(filename.feature: VPC is there)
Scenario: VPC Flow Logs are defined
Given I have any resource defined
When its type is not aws_vpc_flow_log
Then it must fail Where the 2nd Scenario will first ensure the the first scenario passes and then runs. Sounds like we need documentation with examples about |
Wouldn't this fail on any resource that is not an "aws_vpc?" If we use preconditions, on execution we still end up with the two scenarios stacked on top of each other. e.g.
So we still need to be able capture
in one scenario I tested this to be working
@vrbcntrl could you give it a try? |
I was thinking about simulating "Given I have "resource A" not defined" with the current possible directives. The scenario given above simulates
If we come up with a way to represent the other case
We would end up supporting the functionality of the directive. However, I haven't been able to do so. |
You are right, my example will fail on resources that doesn't have Given I have aws_vpc defined
Given I have any resource defined The scenario will be skipped if there is no |
Thanks @Kudbettin @eerkunt for looking into my issue.
However, I also need to check if aws_flow_log is actually referencing the aws_vpc resource via its vpc_id parameter (which is an optional parameter according to terraform docs) so, I have extended the Scenario as shown below
But the step4 failed with error saying it could not find the aws_vpc parameter in so, it looks like it is checking for that property in all the available resources, not only inside aws_flow_log resource so, not sure how to proceed :( |
Hi @vrbcntrl, With release 1.2.7, my previous response became outdated.
Should not filter the We could use the newly added @noskip tag, which will fail on skip.
Will fail if you have aws_vpc defined but not aws_flow_log. (Line 8 corresponds to However, I couldn't come up with a step that checks for your last step. I've looked into the plan file, there isn't anything resembling |
Hi @Kudbettin , Thanks for your response. Its good to have the so, I have tested your Scenario with However, later I have tested this reference the other way round and it worked :)
please see the attached main.tf and plan json I used for testing I think this works fine as long as both |
Wow! It haven't occurred to me at all to try checking that, or looking into the contents of aws_vpc in general. I'm sorry I hadn't noticed your response. The notification got buried in my inbox :) |
np @Kudbettin |
This issue's conversation is now locked. If you want to continue this discussion please open a new issue. |
** Question : **
<A clear describe of your question. Ex, how can I do [...] for [...] with terraform-compliance ?>
How to check if Resource2 is also defined when Resource1 is defined?
I have an use case where in I need to check VPC Flow logs are enabled when a VPC is created
main.tf:
so, I need my test be something like this
currently we don't have a step def for the step2 mentioned above.
I wrote the below Scenario:
The above test worked fine when I have both aws_vpc and aws_flow_log resources defined, however when I don't have aws_flow_log resource defined, the step2 is been SKIPPED, however ideally I would want step2 to be FAILED when aws_flow_log resource is not defined( because in my case its mandatory for aws_vpc to have aws_flog_log enabled
Any ideas on how to finish my test described above? thanks in advance!
The text was updated successfully, but these errors were encountered: