From 94a54eaf48f8e53a00891ed1702a5c6da93dc571 Mon Sep 17 00:00:00 2001 From: petlitskiy <81190543+petlitskiy@users.noreply.github.com> Date: Sun, 23 Mar 2025 23:05:31 +0200 Subject: [PATCH] Retain S3-backed origin --- cloudfront.cfndsl.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cloudfront.cfndsl.rb b/cloudfront.cfndsl.rb index 9f62881..3b2362a 100644 --- a/cloudfront.cfndsl.rb +++ b/cloudfront.cfndsl.rb @@ -1,5 +1,19 @@ CloudFormation do + dependencies_list = [] + cloudfront_component_name = external_parameters.fetch(:cloudfront_component_name, nil) + if !cloudfront_component_name.nil? + origins.filter{|k, v| (v['source'] == 's3') && (v['type'] == 'create_if_not_exists')}.each do |id, config| + if (origins.filter{|k, v| (v['source'] == 's3')}.map.with_index{|(k,v),i| k.to_s == id ? i.to_i : nil}.compact == [0]) + id = "" + end + CloudFormation_WaitConditionHandle("#{id}Bucket") do + Type 'AWS::CloudFormation::WaitConditionHandle' + end + dependencies_list << "#{id}Bucket" + end + end + export = external_parameters.fetch(:export_name, external_parameters[:component_name]) Condition('WebACLEnabled', FnNot(FnEquals(Ref('WebACL'), ''))) @@ -261,6 +275,7 @@ end CloudFront_Distribution(:Distribution) { + DependsOn dependencies_list DistributionConfig distribution_config Tags tags } @@ -295,4 +310,4 @@ Export FnJoin("-", [Ref("EnvironmentName"), export, "DistributionId"]) end -end +end \ No newline at end of file