belt 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of belt might be problematic. Click here for more details.

@@ -1,15 +1,17 @@
1
- # Frontend hosting — S3 + CloudFront
1
+ # Frontend hosting — S3 + CloudFront<% if @include_dns %>
2
2
  # Custom domain attached when var.domain is set
3
-
4
- resource "random_string" "frontend_suffix" {
3
+ <% else %>
4
+ # Additional frontend '<%= @frontend.name %>' — CloudFront default domain (no Route53)
5
+ <% end %>
6
+ resource "random_string" "<%= @tf_name %>_suffix" {
5
7
  length = 8
6
8
  special = false
7
9
  upper = false
8
10
  }
9
11
 
10
12
  # S3 bucket for frontend static assets
11
- resource "aws_s3_bucket" "frontend" {
12
- bucket = "${var.app_name}-frontend-${var.environment}-${random_string.frontend_suffix.result}"
13
+ resource "aws_s3_bucket" "<%= @tf_name %>" {
14
+ bucket = "${var.app_name}-<%= @bucket_slug %>-${var.environment}-${random_string.<%= @tf_name %>_suffix.result}"
13
15
  force_destroy = true
14
16
 
15
17
  lifecycle {
@@ -17,8 +19,8 @@ resource "aws_s3_bucket" "frontend" {
17
19
  }
18
20
  }
19
21
 
20
- resource "aws_s3_bucket_public_access_block" "frontend" {
21
- bucket = aws_s3_bucket.frontend.id
22
+ resource "aws_s3_bucket_public_access_block" "<%= @tf_name %>" {
23
+ bucket = aws_s3_bucket.<%= @tf_name %>.id
22
24
 
23
25
  block_public_acls = true
24
26
  block_public_policy = true
@@ -26,8 +28,8 @@ resource "aws_s3_bucket_public_access_block" "frontend" {
26
28
  restrict_public_buckets = true
27
29
  }
28
30
 
29
- resource "aws_s3_bucket_server_side_encryption_configuration" "frontend" {
30
- bucket = aws_s3_bucket.frontend.id
31
+ resource "aws_s3_bucket_server_side_encryption_configuration" "<%= @tf_name %>" {
32
+ bucket = aws_s3_bucket.<%= @tf_name %>.id
31
33
 
32
34
  rule {
33
35
  apply_server_side_encryption_by_default {
@@ -38,36 +40,36 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "frontend" {
38
40
  }
39
41
 
40
42
  # CloudFront OAC
41
- resource "aws_cloudfront_origin_access_control" "frontend" {
42
- name = "${var.app_name}-${var.environment}-frontend-oac"
43
- description = "OAC for frontend bucket"
43
+ resource "aws_cloudfront_origin_access_control" "<%= @tf_name %>" {
44
+ name = "${var.app_name}-${var.environment}-<%= @bucket_slug %>-oac"
45
+ description = "OAC for <%= @bucket_slug %> bucket"
44
46
  origin_access_control_origin_type = "s3"
45
47
  signing_behavior = "always"
46
48
  signing_protocol = "sigv4"
47
49
  }
48
50
 
49
51
  # CloudFront distribution
50
- resource "aws_cloudfront_distribution" "frontend" {
52
+ resource "aws_cloudfront_distribution" "<%= @tf_name %>" {
51
53
  origin {
52
- domain_name = aws_s3_bucket.frontend.bucket_regional_domain_name
53
- origin_id = "S3-${aws_s3_bucket.frontend.id}"
54
- origin_access_control_id = aws_cloudfront_origin_access_control.frontend.id
54
+ domain_name = aws_s3_bucket.<%= @tf_name %>.bucket_regional_domain_name
55
+ origin_id = "S3-${aws_s3_bucket.<%= @tf_name %>.id}"
56
+ origin_access_control_id = aws_cloudfront_origin_access_control.<%= @tf_name %>.id
55
57
  }
56
58
 
57
59
  enabled = true
58
60
  is_ipv6_enabled = true
59
61
  default_root_object = "index.html"
60
-
62
+ <% if @include_dns %>
61
63
  # Custom domain aliases (if DNS configured)
62
64
  aliases = local.dns_enabled ? compact([
63
65
  local.app_domain,
64
66
  var.environment == "prod" ? "www.${var.domain}" : ""
65
67
  ]) : []
66
-
68
+ <% end %>
67
69
  default_cache_behavior {
68
70
  allowed_methods = ["GET", "HEAD", "OPTIONS"]
69
71
  cached_methods = ["GET", "HEAD"]
70
- target_origin_id = "S3-${aws_s3_bucket.frontend.id}"
72
+ target_origin_id = "S3-${aws_s3_bucket.<%= @tf_name %>.id}"
71
73
  compress = true
72
74
  viewer_protocol_policy = "redirect-to-https"
73
75
 
@@ -99,22 +101,22 @@ resource "aws_cloudfront_distribution" "frontend" {
99
101
  }
100
102
 
101
103
  viewer_certificate {
102
- cloudfront_default_certificate = !local.dns_enabled
103
- acm_certificate_arn = local.dns_enabled ? aws_acm_certificate_validation.app[0].certificate_arn : null
104
- ssl_support_method = local.dns_enabled ? "sni-only" : null
105
- minimum_protocol_version = local.dns_enabled ? "TLSv1.2_2021" : null
104
+ cloudfront_default_certificate = <%= @include_dns ? '!local.dns_enabled' : 'true' %>
105
+ acm_certificate_arn = <%= @include_dns ? 'local.dns_enabled ? aws_acm_certificate_validation.app[0].certificate_arn : null' : 'null' %>
106
+ ssl_support_method = <%= @include_dns ? 'local.dns_enabled ? "sni-only" : null' : 'null' %>
107
+ minimum_protocol_version = <%= @include_dns ? 'local.dns_enabled ? "TLSv1.2_2021" : null' : 'null' %>
106
108
  }
107
109
 
108
110
  tags = {
109
- Name = "${var.app_name}-${var.environment}-frontend"
111
+ Name = "${var.app_name}-${var.environment}-<%= @bucket_slug %>"
110
112
  Environment = var.environment
111
113
  ManagedBy = "Terraform"
112
114
  }
113
115
  }
114
116
 
115
117
  # S3 bucket policy — CloudFront OAC access only
116
- resource "aws_s3_bucket_policy" "frontend" {
117
- bucket = aws_s3_bucket.frontend.id
118
+ resource "aws_s3_bucket_policy" "<%= @tf_name %>" {
119
+ bucket = aws_s3_bucket.<%= @tf_name %>.id
118
120
 
119
121
  policy = jsonencode({
120
122
  Version = "2012-10-17"
@@ -126,55 +128,59 @@ resource "aws_s3_bucket_policy" "frontend" {
126
128
  Service = "cloudfront.amazonaws.com"
127
129
  }
128
130
  Action = "s3:GetObject"
129
- Resource = "${aws_s3_bucket.frontend.arn}/*"
131
+ Resource = "${aws_s3_bucket.<%= @tf_name %>.arn}/*"
130
132
  Condition = {
131
133
  StringEquals = {
132
- "AWS:SourceArn" = aws_cloudfront_distribution.frontend.arn
134
+ "AWS:SourceArn" = aws_cloudfront_distribution.<%= @tf_name %>.arn
133
135
  }
134
136
  }
135
137
  }
136
138
  ]
137
139
  })
138
140
 
139
- depends_on = [aws_s3_bucket_public_access_block.frontend]
141
+ depends_on = [aws_s3_bucket_public_access_block.<%= @tf_name %>]
140
142
  }
141
-
143
+ <% if @include_dns %>
142
144
  # Route53 record for frontend (app domain → CloudFront)
143
- resource "aws_route53_record" "frontend" {
145
+ resource "aws_route53_record" "<%= @tf_name %>" {
144
146
  count = local.dns_enabled ? 1 : 0
145
147
  zone_id = aws_route53_zone.app[0].zone_id
146
148
  name = local.app_domain
147
149
  type = "A"
148
150
 
149
151
  alias {
150
- name = aws_cloudfront_distribution.frontend.domain_name
151
- zone_id = aws_cloudfront_distribution.frontend.hosted_zone_id
152
+ name = aws_cloudfront_distribution.<%= @tf_name %>.domain_name
153
+ zone_id = aws_cloudfront_distribution.<%= @tf_name %>.hosted_zone_id
152
154
  evaluate_target_health = false
153
155
  }
154
156
  }
155
157
 
156
158
  # www record for prod only
157
- resource "aws_route53_record" "frontend_www" {
159
+ resource "aws_route53_record" "<%= @tf_name %>_www" {
158
160
  count = local.dns_enabled && var.environment == "prod" ? 1 : 0
159
161
  zone_id = aws_route53_zone.app[0].zone_id
160
162
  name = "www.${var.domain}"
161
163
  type = "A"
162
164
 
163
165
  alias {
164
- name = aws_cloudfront_distribution.frontend.domain_name
165
- zone_id = aws_cloudfront_distribution.frontend.hosted_zone_id
166
+ name = aws_cloudfront_distribution.<%= @tf_name %>.domain_name
167
+ zone_id = aws_cloudfront_distribution.<%= @tf_name %>.hosted_zone_id
166
168
  evaluate_target_health = false
167
169
  }
168
170
  }
169
-
170
- output "frontend_bucket_name" {
171
- value = aws_s3_bucket.frontend.id
171
+ <% end %>
172
+ output "<%= @output_prefix %>_bucket_name" {
173
+ value = aws_s3_bucket.<%= @tf_name %>.id
172
174
  }
173
175
 
174
- output "frontend_distribution_id" {
175
- value = aws_cloudfront_distribution.frontend.id
176
+ output "<%= @output_prefix %>_distribution_id" {
177
+ value = aws_cloudfront_distribution.<%= @tf_name %>.id
176
178
  }
177
179
 
178
- output "frontend_url" {
179
- value = local.dns_enabled ? "https://${local.app_domain}" : "https://${aws_cloudfront_distribution.frontend.domain_name}"
180
+ output "<%= @output_prefix %>_url" {
181
+ <% if @include_dns -%>
182
+ value = local.dns_enabled ? "https://${local.app_domain}" : "https://${aws_cloudfront_distribution.<%= @tf_name %>.domain_name}"
183
+ <% else -%>
184
+ value = "https://${aws_cloudfront_distribution.<%= @tf_name %>.domain_name}"
185
+ <% end -%>
180
186
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla
@@ -121,6 +121,7 @@ files:
121
121
  - lib/belt/cli/frontend_deploy_command.rb
122
122
  - lib/belt/cli/frontend_env_command.rb
123
123
  - lib/belt/cli/frontend_env_map.rb
124
+ - lib/belt/cli/frontend_registry.rb
124
125
  - lib/belt/cli/frontend_setup_command.rb
125
126
  - lib/belt/cli/generate_command.rb
126
127
  - lib/belt/cli/generator_registry.rb
@@ -139,12 +140,14 @@ files:
139
140
  - lib/belt/cli/tasks_command.rb
140
141
  - lib/belt/cli/terraform_command.rb
141
142
  - lib/belt/cli/views_command.rb
143
+ - lib/belt/cli/zip_artifact_builder.rb
142
144
  - lib/belt/configuration.rb
143
145
  - lib/belt/controllers/welcome_controller.rb
144
146
  - lib/belt/docs/backups.md
145
147
  - lib/belt/docs/console.md
146
148
  - lib/belt/docs/controllers.md
147
149
  - lib/belt/docs/deployment.md
150
+ - lib/belt/docs/frontend.md
148
151
  - lib/belt/docs/generators.md
149
152
  - lib/belt/docs/lambda_handler.md
150
153
  - lib/belt/docs/models.md