From 3661487bdfe8d8a95b68c557260dec94eab09eb2 Mon Sep 17 00:00:00 2001 From: Brian Ojeda <9335829+sgtoj@users.noreply.github.com> Date: Mon, 17 Jul 2023 14:16:56 +0000 Subject: [PATCH] dev: fix all issues with s3-website example --- examples/s3-website/fixtures/website/Dockerfile | 4 +++- examples/s3-website/main.tf | 17 ++++++++++++----- examples/s3-website/output.tf | 3 +++ 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 examples/s3-website/output.tf diff --git a/examples/s3-website/fixtures/website/Dockerfile b/examples/s3-website/fixtures/website/Dockerfile index 7bd71f2..b51b149 100644 --- a/examples/s3-website/fixtures/website/Dockerfile +++ b/examples/s3-website/fixtures/website/Dockerfile @@ -13,4 +13,6 @@ FROM alpine:latest as package COPY --from=build /opt/app/assets/ /opt/app/dist/ RUN apk add zip \ - && cd /opt/app/dist + && cd /opt/app/dist \ + && zip -r /tmp/package.zip . + diff --git a/examples/s3-website/main.tf b/examples/s3-website/main.tf index 942bb33..92e4398 100755 --- a/examples/s3-website/main.tf +++ b/examples/s3-website/main.tf @@ -4,8 +4,7 @@ module "artifact_packager" { docker_build_context = "${path.module}/fixtures/website" docker_build_target = "package" - artifact_src_type = "directory" - artifact_src_path = "/opt/app/dist/" + artifact_src_path = "/tmp/package.zip" artifact_dst_directory = "${path.module}/dist" } @@ -16,8 +15,8 @@ resource "random_string" "website_bucket_random_suffix" { } resource "aws_s3_bucket" "website_bucket" { - bucket = "example-tf-aws-zip-uploader-${random_string.website_bucket_random_suffix.result}" - acl = "public-read" + bucket = "example-tf-aws-zip-uploader-${random_string.website_bucket_random_suffix.result}" + force_destroy = true website { index_document = "index.html" @@ -27,6 +26,14 @@ resource "aws_s3_bucket" "website_bucket" { module "s3_zip_uploader" { source = "../../" - artifact_src_local_path = module.artifact_packager.artifact_dst_path + artifact_src_local_path = module.artifact_packager.artifact_package_path artifact_dst_bucket_arn = aws_s3_bucket.website_bucket.arn + + depends_on = [ + module.artifact_packager + ] +} + +data "aws_s3_objects" "website_assets" { + bucket = aws_s3_bucket.website_bucket.id } diff --git a/examples/s3-website/output.tf b/examples/s3-website/output.tf new file mode 100644 index 0000000..d5c4c9f --- /dev/null +++ b/examples/s3-website/output.tf @@ -0,0 +1,3 @@ +output "bucket_objects" { + value = data.aws_s3_objects.website_assets.keys +}