generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdata_source_cloudinit_config.go
More file actions
120 lines (107 loc) · 4.93 KB
/
data_source_cloudinit_config.go
File metadata and controls
120 lines (107 loc) · 4.93 KB
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
// Copyright IBM Corp. 2019, 2026
// SPDX-License-Identifier: MPL-2.0
package provider
import (
"context"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)
var (
_ datasource.DataSourceWithValidateConfig = (*configDataSource)(nil)
)
type configDataSource struct{}
func (d *configDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_config"
}
func (d *configDataSource) ValidateConfig(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) {
var cloudinitConfig configModel
resp.Diagnostics.Append(req.Config.Get(ctx, &cloudinitConfig)...)
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(cloudinitConfig.validate(ctx)...)
}
func (d *configDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Blocks: map[string]schema.Block{
"part": schema.ListNestedBlock{
Validators: []validator.List{
listvalidator.IsRequired(),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"content_type": schema.StringAttribute{
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
Optional: true,
Computed: true,
MarkdownDescription: "A MIME-style content type to report in the header for the part. Defaults to `text/plain`",
},
"content": schema.StringAttribute{
Required: true,
MarkdownDescription: "Body content for the part.",
},
"filename": schema.StringAttribute{
Optional: true,
MarkdownDescription: "A filename to report in the header for the part.",
},
"merge_type": schema.StringAttribute{
Optional: true,
MarkdownDescription: "A value for the `X-Merge-Type` header of the part, to control " +
"[cloud-init merging behavior](https://cloudinit.readthedocs.io/en/latest/reference/merging.html).",
},
},
},
MarkdownDescription: "A nested block type which adds a file to the generated cloud-init configuration. Use multiple " +
"`part` blocks to specify multiple files, which will be included in order of declaration in the final MIME document.",
},
},
Attributes: map[string]schema.Attribute{
"gzip": schema.BoolAttribute{
Optional: true,
Computed: true,
MarkdownDescription: "Specify whether or not to gzip the `rendered` output. Defaults to `true`.",
},
"base64_encode": schema.BoolAttribute{
Optional: true,
Computed: true,
MarkdownDescription: "Specify whether or not to base64 encode the `rendered` output. Defaults to `true`, and cannot be disabled if gzip is `true`.",
},
"boundary": schema.StringAttribute{
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
Optional: true,
Computed: true,
MarkdownDescription: "Specify the Writer's default boundary separator. Defaults to `MIMEBOUNDARY`.",
},
"rendered": schema.StringAttribute{
Computed: true,
MarkdownDescription: "The final rendered multi-part cloud-init config.",
},
"id": schema.StringAttribute{
Computed: true,
MarkdownDescription: "[CRC-32](https://pkg.go.dev/hash/crc32) checksum of `rendered` cloud-init config.",
},
},
MarkdownDescription: "Renders a [multi-part MIME configuration](https://cloudinit.readthedocs.io/en/latest/explanation/format.html#mime-multi-part-archive) " +
"for use with [cloud-init](https://cloudinit.readthedocs.io/en/latest/).\n\n" +
"Cloud-init is a commonly-used startup configuration utility for cloud compute instances. It accepts configuration via provider-specific " +
"user data mechanisms, such as `user_data` for Amazon EC2 instances. Multi-part MIME is one of the data formats it accepts. For more information, " +
"see [User-Data Formats](https://cloudinit.readthedocs.io/en/latest/explanation/format.html) in the cloud-init manual.\n\n" +
"This is not a generalized utility for producing multi-part MIME messages. Its feature set is specialized for cloud-init multi-part MIME messages.",
}
}
func (d *configDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var cloudinitConfig configModel
resp.Diagnostics.Append(req.Config.Get(ctx, &cloudinitConfig)...)
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(cloudinitConfig.update(ctx)...)
resp.Diagnostics.Append(resp.State.Set(ctx, cloudinitConfig)...)
}