-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Modify directory search logic to look for
required_providers
w…
…ithin the Terraform files and ignore file paths with `wrappers` in them (#14)
- Loading branch information
1 parent
1c564ff
commit 1378076
Showing
29 changed files
with
2,047 additions
and
17 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
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,30 @@ | ||
import json | ||
import mmap | ||
import os | ||
import re | ||
from glob import glob | ||
|
||
|
||
def get_directories(): | ||
""" | ||
Return all Terraform (*.tf) files that contain the `required_version` | ||
string, but does not contain `wrapper` in the path. | ||
""" | ||
|
||
terraform_files = glob('./**/*.tf', recursive=True) | ||
directories = [] | ||
|
||
for file in terraform_files: | ||
file_size = os.stat(file) | ||
|
||
if file_size.st_size > 0: | ||
with open(file, 'rb', 0) as rfile: | ||
contents = mmap.mmap(rfile.fileno(), 0, access=mmap.ACCESS_READ) | ||
if contents.find(b'required_version') != -1 and 'wrapper' not in file: | ||
directories.append(file) | ||
|
||
return json.dumps([x.replace('/versions.tf', '') for x in directories if not re.match(r'^.+/_', x)]) | ||
|
||
|
||
if __name__ == '__main__': | ||
print(get_directories()) |
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 @@ | ||
locals {} |
File renamed without changes.
File renamed without changes.
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,14 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
terraform { | ||
required_version = ">= 0.14" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 3.0" | ||
} | ||
} | ||
} |
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 @@ | ||
locals {} |
Empty file.
Empty file.
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,14 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
terraform { | ||
required_version = ">= 0.13" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 2.0" | ||
} | ||
} | ||
} |
Oops, something went wrong.