Skip to content

Commit

Permalink
feat(analyzer): added support to Cloud Development Kit for Terraform …
Browse files Browse the repository at this point in the history
…(CDKTF) (#4770)
  • Loading branch information
rafaela-soares authored Feb 1, 2022
1 parent 8683d63 commit b38bc28
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"//": {
"metadata": {
"backend": "local",
"stackName": "cdktf-test",
"version": "0.9.0"
},
"outputs": {}
},
"provider": {
"aws": [
{
"region": "us-east-1"
}
]
},
"resource": {
"aws_instance": {
"cdktf-test": {
"//": {
"metadata": {
"path": "cdktf-test/cdktf-test",
"uniqueId": "cdktf-test"
}
},
"ami": "ami-1212f123",
"instance_type": "t2.micro",
"monitoring": true
}
}
},
"terraform": {
"backend": {
"local": {
"path": "/terraform.cdktf-test.tfstate"
}
},
"required_providers": {
"aws": {
"source": "aws",
"version": "~> 3.0"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"//": {
"metadata": {
"backend": "local",
"stackName": "cdktf-test",
"version": "0.9.0"
},
"outputs": {}
},
"provider": {
"aws": [
{
"region": "us-east-1"
}
]
},
"resource": {
"aws_instance": {
"cdktf-test": {
"//": {
"metadata": {
"path": "cdktf-test/cdktf-test",
"uniqueId": "cdktf-test"
}
},
"ami": "ami-1212f123",
"instance_type": "t2.micro",
"monitoring": false
}
}
},
"terraform": {
"backend": {
"local": {
"path": "/terraform.cdktf-test.tfstate"
}
},
"required_providers": {
"aws": {
"source": "aws",
"version": "~> 3.0"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
"severity": "INFO",
"line": 10,
"fileName": "positive4.tf"
},
{
"queryName": "EC2 Instance Monitoring Disabled",
"severity": "INFO",
"line": 28,
"fileName": "positive5.json"
}
]
11 changes: 11 additions & 0 deletions docs/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ KICS supports some official modules for AWS that can be found on [Terraform regi

Currently, KICS does not support unofficial or custom modules.

### Cloud Development Kit for Terraform (CDKTF)

KICS supports scanning CDKTF output JSON. It recognizes it through the fields `metadata`, `stackName`, and `terraform`.

To get your CDKTF output JSON, run the following command inside the directory that contains your app:
```
cdktf synth
```

You can also run the command `cdktf synth --json` to display it in the terminal.

### Limitations

#### Ansible
Expand Down
13 changes: 13 additions & 0 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ var (
tfPlanRegexRC = regexp.MustCompile("\\s*\"resource_changes\":")
tfPlanRegexConf = regexp.MustCompile("\\s*\"configuration\":")
tfPlanRegexTV = regexp.MustCompile("\\s*\"terraform_version\":")
cdkTfRegexMetadata = regexp.MustCompile("\\s*\"metadata\":")
cdkTfRegexStackName = regexp.MustCompile("\\s*\"stackName\":")
cdkTfRegexTerraform = regexp.MustCompile("\\s*\"terraform\":")
blueprintArtifactsRegexKind = regexp.MustCompile("(\\s*\"kind\":)|(\\s*kind:)")
blueprintArtifactsRegexProperties = regexp.MustCompile("(\\s*\"properties\":)|(\\s*properties:)")
blueprintRegexTargetScope = regexp.MustCompile("(\\s*\"targetScope\":)|(\\s*targetScope:)")
Expand Down Expand Up @@ -181,6 +184,13 @@ var types = map[string]regexSlice{
tfPlanRegexTV,
},
},
"cdkTf": {
[]*regexp.Regexp{
cdkTfRegexMetadata,
cdkTfRegexStackName,
cdkTfRegexTerraform,
},
},
"blueprintsartifacts": {
[]*regexp.Regexp{
blueprintArtifactsRegexKind,
Expand Down Expand Up @@ -254,6 +264,9 @@ func checkContent(path string, results, unwanted chan<- string, ext string) {

func checkReturnType(path, returnType, ext string, content []byte) string {
if returnType != "" {
if returnType == "cdkTf" {
return "terraform"
}
if returnType == "blueprint" || returnType == "blueprintsartifacts" {
return arm
}
Expand Down

0 comments on commit b38bc28

Please sign in to comment.