diff --git a/README.md b/README.md
index 064a6b1..26bda28 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,7 @@ This project creates and manages resources within an AWS account for infrastruct
| [external](#provider\_external) | 2.3.3 |
| [null](#provider\_null) | >= 3.2.2 |
| [random](#provider\_random) | >= 3.6.0 |
+| [terraform](#provider\_terraform) | n/a |
## Resources
@@ -347,6 +348,7 @@ This project creates and manages resources within an AWS account for infrastruct
| [null_resource.infrastructure_ecs_cluster_service_blue_green_create_codedeploy_deployment](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [random_password.infrastructure_ecs_cluster_service_cloudfront_bypass_protection_secret](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
| [random_password.infrastructure_rds_root](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
+| [terraform_data.infrastructure_ecs_cluster_service_env_file](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
| [archive_file.ecs_cluster_infrastructure_draining_lambda](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source |
| [archive_file.ecs_cluster_infrastructure_ecs_asg_diff_metric_lambda](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source |
| [archive_file.ecs_cluster_infrastructure_pending_task_metric_lambda](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source |
diff --git a/ecs-cluster-infrastructure-service-codedeploy-blue-green.tf b/ecs-cluster-infrastructure-service-codedeploy-blue-green.tf
index 3678524..80a41c0 100644
--- a/ecs-cluster-infrastructure-service-codedeploy-blue-green.tf
+++ b/ecs-cluster-infrastructure-service-codedeploy-blue-green.tf
@@ -173,5 +173,6 @@ resource "null_resource" "infrastructure_ecs_cluster_service_blue_green_create_c
depends_on = [
aws_codepipeline.infrastructure_ecs_cluster_service,
+ terraform_data.infrastructure_ecs_cluster_service_env_file,
]
}
diff --git a/ecs-cluster-infrastructure-service.tf b/ecs-cluster-infrastructure-service.tf
index a776983..8aa84f1 100644
--- a/ecs-cluster-infrastructure-service.tf
+++ b/ecs-cluster-infrastructure-service.tf
@@ -151,6 +151,25 @@ resource "aws_iam_role_policy_attachment" "infrastructure_ecs_cluster_service_ta
policy_arn = aws_iam_policy.infrastructure_ecs_cluster_service_task_custom[each.key].arn
}
+
+resource "terraform_data" "infrastructure_ecs_cluster_service_env_file" {
+ for_each = local.infrastructure_ecs_cluster_services
+
+ triggers_replace = [
+ aws_ecs_service.infrastructure_ecs_cluster_service[each.key].name,
+ aws_s3_bucket.infrastructure_ecs_cluster_service_environment_files[0].bucket,
+ ]
+
+ provisioner "local-exec" {
+ interpreter = ["/bin/bash", "-c"]
+ command = <&2
+ echo " -h - help"
+ echo " -b - Bucket"
+ echo " -k - Key"
+ exit 1
+}
+
+while getopts "b:k:h" opt; do
+ case $opt in
+ b)
+ BUCKET=$OPTARG
+ ;;
+ k)
+ KEY=$OPTARG
+ ;;
+ h)
+ usage
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+if [[
+ -z "$BUCKET" ||
+ -z "$KEY"
+]]
+then
+ usage
+fi
+
+if ! aws s3api head-object --bucket "$BUCKET" --key "$KEY" 2>/dev/null
+then
+ # If the file does not exist, create an empty file
+ touch /tmp/empty_file.txt
+ aws s3api put-object --bucket "$BUCKET" --key "$KEY" --body /tmp/empty_file.txt
+ rm /tmp/empty_file.txt
+ echo "==> Empty file created in S3 bucket"
+else
+ echo "==> File already exists in S3 bucket, skipping creation"
+fi