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

checking a property's value against a regex when its actual value is null #132

Closed
vrbcntrl opened this issue Jul 23, 2019 · 4 comments
Closed
Assignees
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation

Comments

@vrbcntrl
Copy link
Contributor

Hi @eerkunt ,

I have an use case that I am testing i.e. SageMaker Notebook Instance not encrypted with KMS-CMK

my terraform plan json

"planned_values": {
		"root_module": {
			"resources": [
				{
					"address": "aws_sagemaker_notebook_instance.foo",
					"mode": "managed",
					"type": "aws_sagemaker_notebook_instance",
					"name": "foo",
					"provider_name": "aws",
					"schema_version": 0,
					"values": {
						"instance_type": "ml.t2.medium",
						"kms_key_id": null,
						"lifecycle_config_name": null,
						"name": "my-notebook-instance",
						"role_arn": "arn:aws:iam::123456789012:role/S3Access",
						"subnet_id": null,
						"tags": {
							"Name": "foo"
						}
					}
				}
			]
		}
	}

as you can see the kms_key_id property value is null in the plan

my test is that : The kms_key_id value must match the regex ".*kms.*" so I wrote the below BDD

Scenario: AWS SageMaker Notebook Instance not encrypted with KMS-CMK
        Given I have aws_sagemaker_notebook_instance defined
        Then it must contain kms_key_id
        And its value must match the ".*kms.*" regex

when I run the above BDD, all the 3 steps are PASSED even though the kms_key_id value is null in the plan....so not sure why the test is PASSED?

next, I changed the BDD to this

Scenario: AWS SageMaker Notebook Instance not encrypted with KMS-CMK
   Given I have aws_sagemaker_notebook_instance defined
   Then it must contain kms_key_id
   And its value must not be null
   Then its value must match the ".*kms.*" regex

and It failed at 3rd step as expected.

 Scenario: AWS SageMaker Notebook Instance not encrypted with KMS-CMK
        Given I have aws_sagemaker_notebook_instance defined
        Then it must contain kms_key_id
        And its value must not be null
          Failure: kms_key_id property in aws_sagemaker_notebook_instance.foo resource matches with Null/None regex. It is set to None.
        Then its value must match the ".*kms.*" regex

However, I observed one thing that if the property value is not null, then my first BDD works as expected. The behavior changes when the property value is null.

so, I am wondering what is the correct approach to test when the actual property in Terraform is null and we want to check the value against a regex/value?

the first BDD approach or the later?

@eerkunt
Copy link
Member

eerkunt commented Jul 24, 2019

Hello @vrbcntrl,

Thanks for reporting it 🎉

Both approach is valid, so both should work. Looks like you have found a bug.

@eerkunt eerkunt self-assigned this Jul 24, 2019
@eerkunt eerkunt added the bug label Jul 24, 2019
eerkunt added a commit that referenced this issue Jul 24, 2019
@eerkunt
Copy link
Member

eerkunt commented Jul 24, 2019

Could you please have a try with 1.0.29 ?

@eerkunt eerkunt added the waiting for confirmation Workaround/Fix applied, waiting for confirmation label Jul 24, 2019
@vrbcntrl
Copy link
Contributor Author

Thanks @eerkunt for the quick turnaround.

Tested both my above BDDs and they work as expected with 1.0.29.

Thanks again, have a great day!

@eerkunt
Copy link
Member

eerkunt commented Jul 24, 2019

Thanks for the quick validation. 🎉

Closing the issue.

@eerkunt eerkunt closed this as completed Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants