-
Notifications
You must be signed in to change notification settings - Fork 503
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
Deep modules location mis-proccessed. #365
Comments
The commit above is a working fix, I haven't had a chance to look at how you are handling testing in here so I haven't created a PR. |
Hi @salexpdx , We had an exact same issue in the past and the PR raised by @guilhem for the same. Moreover, I tried the same scenario again on my local setup with the latest master. I am not able reproduce the same. Here's how my directory structure looks lik: ➜ ~ tree tf-example
tf-example
├── cloudfront
│ └── main.tf
└── root
└── main.tf
➜ ~ cat tf-example/root/main.tf
provider "aws" {
region = "us-east-1"
}
module "cloudfront" {
source = "../cloudfront"
}
➜ ~ cat tf-example/cloudfront/main.tf
resource "aws_cloudfront_distribution" "s3-distribution-TLS-v1" {
origin {
domain_name = "aws_s3_bucket.b.bucket_regional_domain_name"
origin_id = "local.s3_origin_id"
s3_origin_config {
origin_access_identity = "origin-access-identity/cloudfront/ABCDEFG1234567"
}
}
enabled = true
default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "local.s3_origin_id"
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "https-only"
}
ordered_cache_behavior {
path_pattern = "/content/immutable/*"
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD", "OPTIONS"]
target_origin_id = "local.s3_origin_id"
forwarded_values {
query_string = false
headers = ["Origin"]
cookies {
forward = "none"
}
}
compress = true
viewer_protocol_policy = "allow-all"
}
ordered_cache_behavior {
path_pattern = "/content/*"
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "local.s3_origin_id"
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "allow-all"
}
restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = ["US", "CA", "GB", "DE"]
}
}
viewer_certificate {
cloudfront_default_certificate = true
minimum_protocol_version = "TLSv1" #expected version is TLSv1.1 or TLSv1.2
}
}
locals {
s3_origin_id = "myS3Origin"
} Running terrascan on this directory structure: ➜ ~ terrascan scan -t aws -d ~/tf-example/root
results:
violations:
- rule_name: cloudfrontNoHTTPSTraffic
description: Use encrypted connection between CloudFront and origin server
rule_id: AWS.CloudFront.EncryptionandKeyManagement.High.0407
severity: HIGH
category: Encryption and Key Management
resource_name: s3-distribution-TLS-v1
resource_type: aws_cloudfront_distribution
file: ../cloudfront/main.tf
line: 1
- rule_name: cloudfrontNoHTTPSTraffic
description: Use encrypted connection between CloudFront and origin server
rule_id: AWS.CloudFront.EncryptionandKeyManagement.High.0407
severity: HIGH
category: Encryption and Key Management
resource_name: s3-distribution-TLS-v1
resource_type: aws_cloudfront_distribution
file: ../cloudfront/main.tf
line: 1
- rule_name: cloudfrontNoLogging
description: Ensure that your AWS Cloudfront distributions have the Logging feature enabled in order to track all viewer requests for the content delivered through the Content Delivery Network (CDN).
rule_id: AWS.CloudFront.Logging.Medium.0567
severity: MEDIUM
category: Logging
resource_name: s3-distribution-TLS-v1
resource_type: aws_cloudfront_distribution
file: ../cloudfront/main.tf
line: 1
count:
low: 0
medium: 1
high: 2
total: 3 |
That example only shows a single module depth. I created a quick test case that shows the issue when you embed a module within a module. salexpdx@68c7601 terraform init
terraform plan
terrascan output
|
Address #365 by properly handling submodule path
properly handle nested submodules (#365)
Description
I have a situation where I am using several modules together. For simplicity, we will just call them m1, m2, and m3. m1 is consumed from my main terraform template and it consumes m2 and m3. When I try and run terrascan, it incorrectly parsers the directory in the module as relative to absRootDir instead of relative to the location of m1.
The file system would look like this
/tf/template.tf
/tf/modules/m1/main.tf
/tf/modules/m2/main.tf
/tf/template.tf contains a call like:
/tf/modules/m1/main.tf contains a call like
What I Did
When I run terrascan on the directory though, I get the following error
I tossed some debugging in to see how it is parsing it internally into the module walker function:
The code added at the end of the if statement at line 84 in pkg/iac-providers/terraform/v12/load-dir.go to generate the above is:
I think the mistake is this code here (still in the if statement that starts at 84):
Instead of looking at the req.Path.String, it should be looking at req.Parent.SourceAddr. If that were used instead, it would result in pathToModules containing the following values:
which would get combined with the filepath.Join to result in
The text was updated successfully, but these errors were encountered: