Comments (9)
I understand the need of being able to test with specific resource attributes values but I don't think those values should be in the assert block. The assert block should only describe the expected result of applying the terraform config under certain circumstances (the input values and the mocked data source).
Do you have other example in mind where you'd like more control on the resource attributes ? That would help to design this feature
from terraspec.
A real case I'm dealing with which came up with the thought is
resource "aws_kms_key" "key" {
description = "KMS key 1"
}
resource "aws_iam_role_policy" "policy" {
role = aws_iam_role.role.id
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*",
"kms:ReEncrypt*"
],
"Resource": [
"${aws_kms_key.key.id}"
]
}
EOF
}
resource "aws_iam_role" "role" {
name = "role"
assume_role_policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
},
"Action": "sts:AssumeRole",
"Condition": {
"Bool": {
"aws:MultiFactorAuthPresent": "true"
}
}
}
]
}
EOF
}
Where I want to assert each one of the above however when ids are not set they are only set as nil
aws_iam_role_policy.policy.role : <nil> != at-least-something-unique-for-role-arn
I also was thinking of asserting policies.
from terraspec.
Also I tend to disagree that is doesn't belong in the assert block because it seems the natural place when comparing it with rspec or other mocking systems
expect(thing).to receive(:call_name).with(args).and_return(something)
basically we are expecting the provider to fill in some data that will be used for other things. I'm not sure I understand why you don't want to add the return to the assert block.
from terraspec.
perhaps this would be fine
assert "aws_s3_bucket" "c" {
bucket = "my-tf-test-bucket"
}
mock_resource "aws_s3_bucket" "c" {
return {
id = "arn:aws:s3::0000000000:my-tf-test-bucket"
}
}
from terraspec.
if its language you could change it to
expect "aws_s3_bucket" "c" {
bucket = "my-tf-test-bucket"
return {
id = "arn:aws:s3::0000000000:my-tf-test-bucket"
}
}
from terraspec.
indeed, that's better with expect
rather than assert
. And it's easier to read (and write) with a single expect
block rather than splitting it betwen an assert
block and a mock
one 👍
from terraspec.
Hello @tomelliot16
I've started implemented support for mocking return values or resources in the mock-return
branch.
It's still work in progress but you can start testing it if you want
from terraspec.
@nhurel I've gotten my team to work on this from Acquia acquia#1 I will open a PR to this repo
from terraspec.
https://github.com/nhurel/terraspec/pull/10/files
from terraspec.
Related Issues (18)
- Mac is hitting issue with FD HOT 3
- Go get fails for 0.6.2 HOT 2
- tfvars files are ignored HOT 4
- Terraform v0.14.x HOT 3
- Mocks cannot validate inputs from expected resources HOT 1
- Issues with 0.14 HOT 3
- question: structure for project with multiple modules HOT 4
- Terraspec is crashing with SIGSEGV error HOT 5
- Newest version of AWS Provider issue causes rpc error HOT 2
- Issue in 0.2.0 HOT 2
- Mocking module variables HOT 2
- Modules values are overriding all of that resource type. HOT 5
- Feature Request: Add the ability to stub out modules HOT 1
- Use and support Terraform 1.x HOT 5
- Provide a Dockerfile HOT 1
- terraform.workspace variable does not seem supported HOT 4
- Terraspec does not find providers in terraform.d folder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraspec.