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

properly handle nested submodules (#365) #373

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/iac-providers/terraform/v12/load-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ func (*TfV12) LoadIacDir(absRootDir string) (allResourcesConfig output.AllResour
var pathToModule string
if isLocalSourceAddr(req.SourceAddr) {
// determine the absolute path from root module to the sub module
// using *configs.ModuleRequest.Path field
pathToModule = filepath.Join(absRootDir, req.Parent.SourceAddr, req.SourceAddr)
zap.S().Debugf("processing local module %q", req.SourceAddr)
// since we start at the end of the path, we need to assemble
// the parts in reverse order

pathToModule = req.SourceAddr
for p := req.Parent; p != nil; p = p.Parent {
pathToModule = filepath.Join(p.SourceAddr, pathToModule)
}
pathToModule = filepath.Join(absRootDir, pathToModule)
zap.S().Debugf("processing local module %q", pathToModule)
} else {
// temp dir to download the remote repo
tempDir := filepath.Join(os.TempDir(), utils.GenRandomString(6))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "m4projectid" {
type = string
default = "asdfasdf"
}

module "m4a" {
source = "./modules/m4a"
m4aprojectid = var.m4projectid
}

resource "aws_s3_bucket" "bucket" {
bucket = var.m4projectid
policy = module.m4a.fullbucketpolicy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable "m4aprojectid" {
type = string
default = "asdfasdf"
}

module "m4b" {
source = "../m4b"
m4bversionyear = "2012"
m4bversionmonth = "10"
m4bversionday = "17"
m4bbucketname = module.m4c.fullbucketname
}
module "m4c" {
source = "../m4c"
m4cbucketname = var.m4aprojectid
m4cenvironment = "dev"
}


resource "aws_s3_bucket" "bucket4a" {
bucket = module.m4c.fullbucketname
policy = module.m4b.fullbucketpolicy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
variable "m4bversionyear" {
type = string
}
variable "m4bversionmonth" {
type = string
}
variable "m4bversionday" {
type = string
}
variable "m4bbucketname" {
type = string
}
data "aws_iam_policy_document" "readbuckets" {
source_json = <<EOF
{
"Version":"${var.m4bversionyear}-${var.m4bversionmonth}-${var.m4bversionday}",
"Statement":[
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::${var.m4bbucketname}/*"]
}
]
}
EOF
}

output "fullbucketpolicy" {
value = data.aws_iam_policy_document.readbuckets.json
}
output "BucketARN" {
value = var.m4bbucketname
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "m4cbucketname" {
type = string
}
variable "m4cenvironment" {
type = string
}

output "fullbucketname" {
value = "${var.m4cbucketname}-${var.m4cenvironment}"
}
output "sourcebucketname" {
value = var.m4cbucketname
}
output "sourceenvironment" {
value = var.m4cenvironment
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ module "m1" {
source = "./modules/m1"
m1projectid = "tf-test-project"
}

module "m4" {
source = "./modules/m4"
m4projectid = "tf-test-project-2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
"bucket": "${module.m3.fullbucketname}",
"policy": "${module.m2.fullbucketpolicy}"
}
},
{
"id": "aws_s3_bucket.bucket",
"name": "bucket",
"source": "modules/m4/main.tf",
"line": 11,
"type": "aws_s3_bucket",
"config": {
"bucket": "tf-test-project-2",
"policy": "${module.m4a.fullbucketpolicy}"
}
},
{
"id": "aws_s3_bucket.bucket4a",
"name": "bucket4a",
"source": "modules/m4/modules/m4a/main.tf",
"line": 20,
"type": "aws_s3_bucket",
"config": {
"bucket": "${module.m4c.fullbucketname}",
"policy": "${module.m4b.fullbucketpolicy}"
}
}
]
}