diff --git a/Makefile b/Makefile index 2887af7..b9b8b83 100644 --- a/Makefile +++ b/Makefile @@ -9,11 +9,27 @@ endif export appenv := $(shell echo "$(environment)" | tr '[:upper:]' '[:lower:]') export TF_VAR_appenv := $(appenv) -.PHONY: test deploy lint_handler test_handler build_handler release_handler plan_terraform apply_terraform clean +.PHONY: test deploy check lint_handler test_handler build_handler release_handler plan_terraform validate_terraform init_terraform apply_terraform apply_terraform_tests destroy_terraform_tests clean test: test_handler plan_terraform deploy: build_handler apply_terraform +check: +ifeq ($(strip $(backend_bucket)),) + @echo "backend_bucket must be provided" + @exit 1 +endif +ifeq ($(strip $(TF_VAR_appenv)),) + @echo "TF_VAR_appenv must be provided" + @exit 1 +else + @echo "appenv: $(TF_VAR_appenv)" +endif +ifeq ($(strip $(backend_key)),) + @echo "backend_key must be provided" + @exit 1 +endif + lint_handler: make -C handler lint @@ -26,17 +42,25 @@ build_handler: release_handler: make -C handler release -plan_terraform: - make -C terraform plan +plan_terraform: validate_terraform + terraform plan + make -C tests plan + +validate_terraform: init_terraform + terraform validate + +init_terraform: check + [[ -d release ]] || mkdir release + [[ -e release/grace-inventory-lambda.zip ]] || touch release/grace-inventory-lambda.zip + terraform init -backend-config="bucket=$(backend_bucket)" -backend-config="key=$(backend_key)" -apply_terraform: - make -C terraform apply +apply_terraform: apply_terraform_tests apply_terraform_tests: - make -C terraform/tests apply + make -C tests apply destroy_terraform_tests: - make -C terraform/tests destroy + make -C tests destroy clean: make -C handler clean diff --git a/README.md b/README.md index ed9d4dd..bb7fb2a 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ download the binary release from Github or compile the handler locally. ```bash mkdir -p release cd release -curl -L https://github.com/GSA/grace-inventory/releases/download/v0.1.0/grace-inventory-lambda.zip -o grace-inventory-lambda.zip +curl -L https://github.com/GSA/grace-inventory/releases/download/v0.1.1/grace-inventory-lambda.zip -o grace-inventory-lambda.zip cd .. ``` @@ -148,7 +148,7 @@ include the following in your root terraform module: ``` module "example_self" { - source = "github.com/GSA/grace-inventory/terraform" + source = "github.com/GSA/grace-inventory?ref=v0.1.1" source_file = "../../release/grace-inventory-lambda.zip" appenv = "environment" project_name = "your-project" diff --git a/terraform/cloudwatch.tf b/cloudwatch.tf similarity index 100% rename from terraform/cloudwatch.tf rename to cloudwatch.tf diff --git a/terraform/examples/example-master.tf b/examples/example-master.tf similarity index 93% rename from terraform/examples/example-master.tf rename to examples/example-master.tf index dc137d9..67f11c2 100644 --- a/terraform/examples/example-master.tf +++ b/examples/example-master.tf @@ -6,5 +6,5 @@ module "example_master" { accounts_info = "" source_file = "../../release/grace-inventory-lambda.zip" appenv = "development" - //project_name = "grace" + project_name = "grace" } diff --git a/terraform/examples/example-mgmt-all.tf b/examples/example-mgmt-all.tf similarity index 94% rename from terraform/examples/example-mgmt-all.tf rename to examples/example-mgmt-all.tf index 362ec0f..49620db 100644 --- a/terraform/examples/example-mgmt-all.tf +++ b/examples/example-mgmt-all.tf @@ -9,5 +9,5 @@ module "example_mgmt_all" { master_role_name = "AssumableRole" source_file = "../../release/grace-inventory-lambda.zip" appenv = "development" - //project_name = "grace" + project_name = "grace" } diff --git a/examples/example-self.tf b/examples/example-self.tf new file mode 100644 index 0000000..ae411c5 --- /dev/null +++ b/examples/example-self.tf @@ -0,0 +1,8 @@ +// The default behavior is to inventory only the account the lambda function +// is installed in (i.e. accounts_info = "self" +module "example_self" { + source = "github.com/GSA/grace-inventory/terraform" + source_file = "../../release/grace-inventory-lambda.zip" + appenv = "development" + project_name = "grace" +} diff --git a/terraform/examples/versions.tf b/examples/versions.tf similarity index 100% rename from terraform/examples/versions.tf rename to examples/versions.tf diff --git a/terraform/iam.tf b/iam.tf similarity index 100% rename from terraform/iam.tf rename to iam.tf diff --git a/terraform/kms.tf b/kms.tf similarity index 100% rename from terraform/kms.tf rename to kms.tf diff --git a/terraform/lambda.tf b/lambda.tf similarity index 100% rename from terraform/lambda.tf rename to lambda.tf diff --git a/terraform/main.tf b/main.tf similarity index 100% rename from terraform/main.tf rename to main.tf diff --git a/terraform/outputs.tf b/outputs.tf similarity index 100% rename from terraform/outputs.tf rename to outputs.tf diff --git a/terraform/s3.tf b/s3.tf similarity index 100% rename from terraform/s3.tf rename to s3.tf diff --git a/terraform/Makefile b/terraform/Makefile deleted file mode 100644 index 7672343..0000000 --- a/terraform/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -.PHONY: check apply plan validate init -check: -ifeq ($(strip $(backend_bucket)),) - @echo "backend_bucket must be provided" - @exit 1 -endif -ifeq ($(strip $(TF_VAR_appenv)),) - @echo "TF_VAR_appenv must be provided" - @exit 1 -else - @echo "appenv: $(TF_VAR_appenv)" -endif -ifeq ($(strip $(backend_key)),) - @echo "backend_key must be provided" - @exit 1 -endif - -apply: - make -C tests apply - -plan: validate - terraform plan - make -C tests plan - -validate: init - terraform validate - # terrascan --location . --tests all - -init: check - [[ -d ../release ]] || mkdir ../release - [[ -e ../release/grace-inventory-lambda.zip ]] || touch ../release/grace-inventory-lambda.zip - terraform init -backend-config="bucket=$(backend_bucket)" -backend-config="key=$(backend_key)" diff --git a/terraform/examples/example-self.tf b/terraform/examples/example-self.tf deleted file mode 100644 index c74218a..0000000 --- a/terraform/examples/example-self.tf +++ /dev/null @@ -1,8 +0,0 @@ -// The default behavior is to inventory only the account the lambda function -// is installed in (i.e. accounts_info = "self" -module "example_self" { - source = "github.com/GSA/grace-inventory/terraform" - source_file = "../../release/grace-inventory-lambda.zip" - appenv = "development" - //project_name = "grace" -} diff --git a/terraform/tests/Makefile b/tests/Makefile similarity index 100% rename from terraform/tests/Makefile rename to tests/Makefile diff --git a/terraform/tests/integration_test.tf b/tests/integration_test.tf similarity index 81% rename from terraform/tests/integration_test.tf rename to tests/integration_test.tf index d227b1c..34e5c31 100644 --- a/terraform/tests/integration_test.tf +++ b/tests/integration_test.tf @@ -12,7 +12,7 @@ provider "aws" { // if accounts_info = "" and master_account_id and master_role_name are set // and the roles are assumable by the Lambda function's IAM role module "integration_test" { - // source = "github.com/GSA/grace-inventory/terraform?ref=latest" + // source = "github.com/GSA/grace-inventory?ref=latest" source = "../" accounts_info = "self" project_name = "grace" @@ -20,5 +20,5 @@ module "integration_test" { master_account_id = var.master_account_id master_role_name = var.master_role_name tenant_role_name = var.tenant_role_name - source_file = "../../release/grace-inventory-lambda.zip" + source_file = "../release/grace-inventory-lambda.zip" } diff --git a/terraform/tests/variables.tf b/tests/variables.tf similarity index 100% rename from terraform/tests/variables.tf rename to tests/variables.tf diff --git a/terraform/tests/versions.tf b/tests/versions.tf similarity index 100% rename from terraform/tests/versions.tf rename to tests/versions.tf diff --git a/terraform/variables.tf b/variables.tf similarity index 100% rename from terraform/variables.tf rename to variables.tf diff --git a/terraform/versions.tf b/versions.tf similarity index 100% rename from terraform/versions.tf rename to versions.tf