Skip to content

Commit cbfa36d

Browse files
authored
Merge pull request #82 from provectus/DQ-132
[MAINTENANCE] Terraform: move S3 resources to a new module
2 parents 6a1ddb5 + 52e409e commit cbfa36d

File tree

26 files changed

+263
-64
lines changed

26 files changed

+263
-64
lines changed

.github/workflows/run-integration-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ jobs:
2222
terraform_version: 1.3.3
2323
- name: Terraform init
2424
run: |
25-
cd ./examples/localstack
25+
cd ./tests/integration_tests/infra
2626
terraform init
2727
- name: Terraform apply
2828
run: |
29-
cd ./examples/localstack
30-
terraform apply -target=module.integration_tests_data_qa.aws_s3_object.great_expectations_yml -target=module.integration_tests_data_qa.aws_s3_object.test_configs -target=module.integration_tests_data_qa.aws_s3_object.pipeline_config -target=module.integration_tests_data_qa.aws_s3_object.pks_config -target=module.integration_tests_data_qa.aws_s3_object.mapping_config -target=module.integration_tests_data_qa.aws_s3_object.expectations_store -target=module.integration_tests_data_qa.aws_s3_object.test_config_manifest -auto-approve
29+
cd ./tests/integration_tests/infra
30+
terraform apply -auto-approve
3131
- name: check localstack
3232
run: |
3333
curl http://localhost:4566/_localstack/health -i
@@ -40,4 +40,4 @@ jobs:
4040
cd ./tests/integration_tests/test_data_tests
4141
docker build -t integration-tests:latest .
4242
- name: Run tests
43-
run: docker run --env BUCKET=integration-test-bucket --env S3_HOST=172.17.0.1 --env S3_PORT=4566 integration-tests
43+
run: docker run --env BUCKET=dqg-settings-local --env S3_HOST=172.17.0.1 --env S3_PORT=4566 integration-tests

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ run-localstack:
22
docker run --rm -d -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack:1.3.1
33

44
deploy-qa-infra:
5-
cd ./examples/localstack && \
5+
cd ./tests/integration_tests/infra && \
66
terraform init && \
7-
terraform apply -target=module.integration_tests_data_qa.aws_s3_object.great_expectations_yml -target=module.integration_tests_data_qa.aws_s3_object.test_configs -target=module.integration_tests_data_qa.aws_s3_object.pipeline_config -target=module.integration_tests_data_qa.aws_s3_object.pks_config -target=module.integration_tests_data_qa.aws_s3_object.mapping_config -target=module.integration_tests_data_qa.aws_s3_object.expectations_store -target=module.integration_tests_data_qa.aws_s3_object.test_config_manifest -auto-approve
7+
terraform apply -auto-approve
88

99
build-data-test-img:
1010
cd ./functions/data_test && \
@@ -23,7 +23,7 @@ build-unit-tests-img: build-data-test-img
2323

2424
host := host.docker.internal
2525
port:= 4566
26-
qa_bucket = integration-test-bucket
26+
qa_bucket = dqg-settings-local
2727

2828
run-integration-tests: build-data-test-img build-data-test-tests-img
2929
cd $(integration_tests_dir)

examples/localstack/README.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/localstack/main.tf

Lines changed: 0 additions & 31 deletions
This file was deleted.

terraform/iam.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ resource "aws_iam_policy" "basic_lambda_policy" {
1717
"s3:*"
1818
],
1919
"Resource" : [
20-
"arn:aws:s3:::${aws_s3_bucket.settings_bucket.bucket}",
21-
"arn:aws:s3:::${aws_s3_bucket.settings_bucket.bucket}/*",
20+
"arn:aws:s3:::${module.s3_bucket.bucket_name}",
21+
"arn:aws:s3:::${module.s3_bucket.bucket_name}/*",
2222
]
2323
},
2424
{

terraform/lambda_allure_report.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module "lambda_allure_report" {
1010

1111
environment_variables = merge({
1212
ENVIRONMENT = var.environment
13-
BUCKET = aws_s3_bucket.settings_bucket.bucket
13+
BUCKET = module.s3_bucket.bucket_name
1414
REPORTS_WEB = module.reports_gateway.s3_gateway_address
1515
DYNAMODB_TABLE = aws_dynamodb_table.data_qa_report.name
1616
}, var.allure_report_extra_vars)

terraform/lambda_data_test.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module "lambda_data_test" {
1010

1111
environment_variables = merge({
1212
ENVIRONMENT = var.environment
13-
BUCKET = aws_s3_bucket.settings_bucket.bucket
13+
BUCKET = module.s3_bucket.bucket_name
1414
REPORTS_WEB = module.reports_gateway.s3_gateway_address
1515
DYNAMODB_TABLE = aws_dynamodb_table.data_qa_report.name
1616
REDSHIFT_DB = var.redshift_db_name

terraform/lambda_push_report.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
22
default_push_report_env_vars = merge({
33
ENVIRONMENT = var.environment
4-
BUCKET = aws_s3_bucket.settings_bucket.bucket
4+
BUCKET = module.s3_bucket.bucket_name
55
REPORTS_WEB = module.reports_gateway.s3_gateway_address
66
DYNAMODB_TABLE = aws_dynamodb_table.data_qa_report.name
77
JIRA_URL = var.lambda_push_jira_url

terraform/modules.tf

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ module "athena-connector" {
66
data_catalog_name = "dqg-dynamodb-connector-${var.environment}"
77
}
88

9+
module "s3_bucket" {
10+
source = "./modules/s3-configs"
11+
environment = var.environment
12+
13+
data_test_storage_bucket_name = var.data_test_storage_bucket_name
14+
test_coverage_path = var.test_coverage_path
15+
pipeline_config_path = var.pipeline_config_path
16+
pks_path = var.pks_path
17+
sort_keys_path = var.sort_keys_path
18+
mapping_path = var.mapping_path
19+
expectations_store = var.expectations_store
20+
manifest_path = var.manifest_path
21+
great_expectation_path = var.great_expectation_path
22+
}
23+
924
module "basic_slack_alerting" {
1025
count = var.basic_alert_notification_settings == null ? 0 : 1
1126
source = "./modules/alerting"
@@ -22,9 +37,11 @@ module "basic_slack_alerting" {
2237
}
2338

2439
module "reports_gateway" {
25-
source = "./modules/s3-gateway"
40+
source = "./modules/s3-gateway"
41+
depends_on = [module.s3_bucket]
42+
2643
env = var.environment
27-
bucket_name = aws_s3_bucket.settings_bucket.bucket
44+
bucket_name = module.s3_bucket.bucket_name
2845

2946
vpc_id = var.reports_vpc_id
3047
instance_subnet_id = var.reports_subnet_id

terraform/s3.tf renamed to terraform/modules/s3-configs/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ resource "aws_s3_bucket_versioning" "fast-data-qa-bucket" {
2121
resource "aws_s3_object" "great_expectations_yml" {
2222
bucket = aws_s3_bucket.settings_bucket.bucket
2323
content_type = "application/x-yaml"
24-
content = templatefile("${path.module}/../templates/great_expectations.yml", {
24+
content = templatefile("${path.module}/${var.great_expectation_path}", {
2525
bucket = aws_s3_bucket.settings_bucket.bucket
2626
})
2727
key = "${aws_s3_bucket.settings_bucket.bucket}/great_expectations/great_expectations.yml"
28-
etag = md5(templatefile("${path.module}/../templates/great_expectations.yml", {
28+
etag = md5(templatefile("${path.module}/${var.great_expectation_path}", {
2929
bucket = aws_s3_bucket.settings_bucket.bucket
3030
}))
3131
}
@@ -76,12 +76,12 @@ resource "aws_s3_object" "expectations_store" {
7676

7777
resource "aws_s3_object" "test_config_manifest" {
7878
bucket = aws_s3_bucket.settings_bucket.bucket
79-
etag = md5(templatefile("${path.module}/../configs/manifest.json", {
79+
etag = md5(templatefile("${path.module}/${var.manifest_path}", {
8080
env_name = var.environment,
8181
bucket_name = aws_s3_bucket.settings_bucket.bucket
8282
}))
8383
content_type = "application/json"
84-
content = templatefile("${path.module}/../configs/manifest.json",
84+
content = templatefile("${path.module}/${var.manifest_path}",
8585
{
8686
env_name = var.environment,
8787
bucket_name = aws_s3_bucket.settings_bucket.bucket
@@ -165,4 +165,4 @@ resource "aws_s3_bucket_lifecycle_configuration" "delete_old_reports" {
165165
status = "Enabled"
166166
id = "great_expectations_uncommitted"
167167
}
168-
}
168+
}

0 commit comments

Comments
 (0)