/
bucket_website_configuration_schema.go
301 lines (293 loc) · 12 KB
/
bucket_website_configuration_schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package s3
import (
"context"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
superschema "github.com/FrangipaneTeam/terraform-plugin-framework-superschema"
)
func bucketWebsiteConfigurationSchema(_ context.Context) superschema.Schema {
return superschema.Schema{
Resource: superschema.SchemaDetails{
MarkdownDescription: "The `cloudavenue_s3_bucket_website_configuration` resource allows you to manage a configuration to host static websites content. [For more information](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html)",
},
DataSource: superschema.SchemaDetails{
MarkdownDescription: "The `cloudavenue_s3_bucket_website_configuration` data source allows you to retrieve information about a configuration of static websites content. [For more information](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html)",
},
Attributes: superschema.Attributes{
"timeouts": superschema.TimeoutAttribute{
Resource: &superschema.ResourceTimeoutAttribute{
Create: true,
Update: true,
Delete: true,
Read: true,
},
DataSource: &superschema.DatasourceTimeoutAttribute{
Read: true,
},
},
"id": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
Computed: true,
MarkdownDescription: "The ID of the bucket website. This is the same as the bucket name",
},
},
"bucket": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The name of the bucket.",
Required: true,
},
Resource: &schemaR.StringAttribute{
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
"index_document": superschema.SuperSingleNestedAttributeOf[BucketWebsiteConfigurationModelIndexDocument]{
Common: &schemaR.SingleNestedAttribute{
MarkdownDescription: "The name of the index document.",
},
Resource: &schemaR.SingleNestedAttribute{
Optional: true,
},
DataSource: &schemaD.SingleNestedAttribute{
Computed: true,
},
Attributes: superschema.Attributes{
"suffix": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The suffix of the index document.",
},
Resource: &schemaR.StringAttribute{
Required: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("redirect_all_requests_to")),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
},
},
"error_document": superschema.SuperSingleNestedAttributeOf[BucketWebsiteConfigurationModelErrorDocument]{
Common: &schemaR.SingleNestedAttribute{
MarkdownDescription: "The name of the error document for the website.",
},
Resource: &schemaR.SingleNestedAttribute{
Optional: true,
},
DataSource: &schemaD.SingleNestedAttribute{
Computed: true,
},
Attributes: superschema.Attributes{
"key": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The key of the error document.",
},
Resource: &schemaR.StringAttribute{
Required: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("redirect_all_requests_to")),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
},
},
"redirect_all_requests_to": superschema.SuperSingleNestedAttributeOf[BucketWebsiteConfigurationModelRedirectAllRequestsTo]{
Common: &schemaR.SingleNestedAttribute{
MarkdownDescription: "Redirect behavior for every request to this bucket's website endpoint. [For more information](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_website_configuration#redirect_all_requests_to)",
},
Resource: &schemaR.SingleNestedAttribute{
Optional: true,
Validators: []validator.Object{
objectvalidator.ConflictsWith(path.MatchRoot("index_document"), path.MatchRoot("error_document"), path.MatchRoot("routing_rules")),
},
},
DataSource: &schemaD.SingleNestedAttribute{
Computed: true,
},
Attributes: superschema.Attributes{
"hostname": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Name of the host where requests will be redirected.",
},
Resource: &schemaR.StringAttribute{
Required: true,
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"protocol": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Protocol to use when redirecting requests. The default is the protocol that is used in the original request.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf(s3.Protocol_Values()...),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
},
},
"routing_rules": superschema.SuperSetNestedAttributeOf[BucketWebsiteConfigurationModelRoutingRule]{
Common: &schemaR.SetNestedAttribute{
MarkdownDescription: "Rules that define when a redirect is applied and the redirect behavior. [For more information](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_website_configuration#routing_rule)",
},
Resource: &schemaR.SetNestedAttribute{
Optional: true,
Validators: []validator.Set{
setvalidator.ConflictsWith(path.MatchRoot("redirect_all_requests_to")),
},
},
DataSource: &schemaD.SetNestedAttribute{
Computed: true,
},
Attributes: superschema.Attributes{
"condition": superschema.SuperSingleNestedAttributeOf[BucketWebsiteConfigurationModelCondition]{
Common: &schemaR.SingleNestedAttribute{
MarkdownDescription: "Configuration block for describing a condition that must be met for the specified redirect to apply. [For more information](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_website_configuration#condition)",
},
Resource: &schemaR.SingleNestedAttribute{
Optional: true,
},
DataSource: &schemaD.SingleNestedAttribute{
Computed: true,
},
Attributes: superschema.Attributes{
"key_prefix_equals": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The object key name prefix when the redirect is applied. For example, to redirect requests for `ExamplePage.html`, the key prefix will be `ExamplePage.html`. To redirect request for all pages with the prefix `docs/`, the key prefix will be `docs`, which identifies all objects in the docs/ folder.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("redirect_all_requests_to")),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"http_error_code_returned_equals": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The HTTP error code when the redirect is applied. In the event of an error, if the error code equals this value, then the specified redirect is applied. Required when parent element `key_prefix_equals` is specified and parent element `http_redirect` is not.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("redirect_all_requests_to")),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
},
},
"redirect": superschema.SuperSingleNestedAttributeOf[BucketWebsiteConfigurationModelRedirect]{
Common: &schemaR.SingleNestedAttribute{
MarkdownDescription: "Configuration block for redirecting all requests to another host instead of the original host. [For more information](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_website_configuration#redirect)",
},
Resource: &schemaR.SingleNestedAttribute{
Required: true,
},
DataSource: &schemaD.SingleNestedAttribute{
Computed: true,
},
Attributes: superschema.Attributes{
"hostname": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Name of the host where requests will be redirected.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"http_redirect_code": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "HTTP redirect code to use on the response.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("301", "302"),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"protocol": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Protocol to use when redirecting requests. The default is the protocol that is used in the original request.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("http", "https"),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"replace_key_prefix_with": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Object key prefix to use in the redirect request. For example, to redirect requests for all pages with prefix `docs/` (objects in the `docs/` folder) to `documents/`, you can set a condition block with `key_prefix_equals` set to `docs/` and in the redirect set `replace_key_prefix_with` to `/documents`.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("replace_key_with")),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"replace_key_with": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Specific object key to use in the redirect request. For example, redirect request to `error.html`.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("replace_key_prefix_with")),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
},
},
},
},
"website_endpoint": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The website endpoint.",
Computed: true,
},
},
},
}
}