-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Example of using tf-cmd-api show command to write pre-provision test similar to sentinel using groovy and spock authored-by: robert <rdhutto1@gamil.com>
- Loading branch information
1 parent
e5f81cc
commit 9c6675e
Showing
21 changed files
with
2,369 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
resource "aws_s3_bucket" "bucket1" { | ||
bucket = "bucket1" | ||
|
||
versioning { | ||
enabled = true | ||
} | ||
|
||
tags = { | ||
application_id = "cna" | ||
stack_name = "stacked" | ||
created_by = "rhutto@deliveredtech.com" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket" "bucket2" { | ||
bucket = "bucket2" | ||
|
||
versioning { | ||
enabled = true | ||
} | ||
|
||
tags = { | ||
application_id = "cna" | ||
stack_name = "stacked" | ||
created_by = "rhutto@deliveredtech.com" | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
examples/tf-s3/src/test/groovy/tf/s3/S3SentinelSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package tf.s3 | ||
|
||
|
||
import com.deliveredtechnologies.terraform.fluent.api.Terraform | ||
import com.deliveredtechnologies.terraform.fluent.api.TfPlan | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class S3SentinelSpec extends Specification { | ||
|
||
@Shared | ||
TfPlan tfplan; | ||
@Shared | ||
mandatory_tags = [ | ||
"application_id", | ||
"stack_name", | ||
"created_by", | ||
] | ||
|
||
@Unroll("#s3Bucket.address has all the mandatory tags") | ||
def "S3 resources have all mandatory tags"() { | ||
|
||
expect: | ||
hasMandatoryTags(s3Bucket) | ||
|
||
where: | ||
s3Bucket << tfplan.getResourcesByType("aws_s3_bucket") | ||
} | ||
|
||
@Unroll("#s3Bucket.address versioning enabled == true") | ||
def "S3 versioning enabled"() { | ||
|
||
expect: | ||
isVersioningEnabled(s3Bucket) | ||
|
||
where: | ||
s3Bucket << tfplan.getResourcesByType("aws_s3_bucket") | ||
} | ||
|
||
void isVersioningEnabled(Map resource) { | ||
Map m = resource.change.after | ||
assert m.containsKey("versioning") | ||
assert m.versioning[0].enabled == true | ||
} | ||
|
||
void hasMandatoryTags(Map resource) { | ||
mandatory_tags.each {tag -> | ||
Map resourceTags = resource.change.after.tags | ||
assert resourceTags.containsKey(tag) | ||
} | ||
} | ||
|
||
def setupSpec() { | ||
|
||
Terraform terraform = new Terraform().withRootDir('s3_sentinel_demo') | ||
.withProperties([ | ||
noColor: true, | ||
]) | ||
tfplan = terraform.initAndPlan() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.