@@ -11,11 +11,12 @@ import (
11
11
"os"
12
12
"path"
13
13
14
- "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator"
14
+ "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
15
+ "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
15
16
"github.com/hashicorp/terraform-plugin-framework/datasource"
16
- "github.com/hashicorp/terraform-plugin-framework/diag "
17
+ "github.com/hashicorp/terraform-plugin-framework/datasource/schema "
17
18
fwpath "github.com/hashicorp/terraform-plugin-framework/path"
18
- "github.com/hashicorp/terraform-plugin-framework/tfsdk "
19
+ "github.com/hashicorp/terraform-plugin-framework/schema/validator "
19
20
"github.com/hashicorp/terraform-plugin-framework/types"
20
21
)
21
22
@@ -27,140 +28,125 @@ func NewArchiveFileDataSource() datasource.DataSource {
27
28
28
29
type archiveFileDataSource struct {}
29
30
30
- func (d * archiveFileDataSource ) GetSchema (ctx context.Context ) (tfsdk. Schema , diag. Diagnostics ) {
31
- return tfsdk .Schema {
31
+ func (d * archiveFileDataSource ) Schema (ctx context.Context , req datasource. SchemaRequest , resp * datasource. SchemaResponse ) {
32
+ resp . Schema = schema .Schema {
32
33
Description : "Generates an archive from content, a file, or directory of files." ,
33
- Blocks : map [string ]tfsdk .Block {
34
- "source" : {
34
+ Blocks : map [string ]schema .Block {
35
+ "source" : schema. SetNestedBlock {
35
36
Description : "Specifies attributes of a single source file to include into the archive." ,
36
- Attributes : map [string ]tfsdk.Attribute {
37
- "content" : {
38
- Description : "Add this content to the archive with `filename` as the filename." ,
39
- Type : types .StringType ,
40
- Required : true ,
41
- Validators : []tfsdk.AttributeValidator {
42
- schemavalidator .ConflictsWith (
43
- fwpath .MatchRoot ("source_file" ),
44
- fwpath .MatchRoot ("source_dir" ),
45
- fwpath .MatchRoot ("source_content" ),
46
- fwpath .MatchRoot ("source_content_filename" ),
47
- ),
37
+ NestedObject : schema.NestedBlockObject {
38
+ Attributes : map [string ]schema.Attribute {
39
+ "content" : schema.StringAttribute {
40
+ Description : "Add this content to the archive with `filename` as the filename." ,
41
+ Required : true ,
42
+ Validators : []validator.String {
43
+ stringvalidator .ConflictsWith (
44
+ fwpath .MatchRoot ("source_file" ),
45
+ fwpath .MatchRoot ("source_dir" ),
46
+ fwpath .MatchRoot ("source_content" ),
47
+ fwpath .MatchRoot ("source_content_filename" ),
48
+ ),
49
+ },
50
+ },
51
+ "filename" : schema.StringAttribute {
52
+ Description : "Set this as the filename when declaring a `source`." ,
53
+ Required : true ,
48
54
},
49
- },
50
- "filename" : {
51
- Description : "Set this as the filename when declaring a `source`." ,
52
- Type : types .StringType ,
53
- Required : true ,
54
55
},
55
56
},
56
- NestingMode : tfsdk .BlockNestingModeSet ,
57
57
},
58
58
},
59
- Attributes : map [string ]tfsdk .Attribute {
60
- "id" : {
59
+ Attributes : map [string ]schema .Attribute {
60
+ "id" : schema. StringAttribute {
61
61
Description : "The sha1 checksum hash of the output." ,
62
- Type : types .StringType ,
63
62
Computed : true ,
64
63
},
65
- "type" : {
64
+ "type" : schema. StringAttribute {
66
65
Description : "The type of archive to generate. NOTE: `zip` is supported." ,
67
- Type : types .StringType ,
68
66
Required : true ,
69
67
},
70
- "source_content" : {
68
+ "source_content" : schema. StringAttribute {
71
69
Description : "Add only this content to the archive with `source_content_filename` as the filename." ,
72
- Type : types .StringType ,
73
70
Optional : true ,
74
- Validators : []tfsdk. AttributeValidator {
75
- schemavalidator .ConflictsWith (
71
+ Validators : []validator. String {
72
+ stringvalidator .ConflictsWith (
76
73
fwpath .MatchRoot ("source_file" ),
77
74
fwpath .MatchRoot ("source_dir" ),
78
75
),
79
76
},
80
77
},
81
- "source_content_filename" : {
78
+ "source_content_filename" : schema. StringAttribute {
82
79
Description : "Set this as the filename when using `source_content`." ,
83
- Type : types .StringType ,
84
80
Optional : true ,
85
- Validators : []tfsdk. AttributeValidator {
86
- schemavalidator .ConflictsWith (
81
+ Validators : []validator. String {
82
+ stringvalidator .ConflictsWith (
87
83
fwpath .MatchRoot ("source_file" ),
88
84
fwpath .MatchRoot ("source_dir" ),
89
85
),
90
86
},
91
87
},
92
- "source_file" : {
88
+ "source_file" : schema. StringAttribute {
93
89
Description : "Package this file into the archive." ,
94
- Type : types .StringType ,
95
90
Optional : true ,
96
- Validators : []tfsdk. AttributeValidator {
97
- schemavalidator .ConflictsWith (
91
+ Validators : []validator. String {
92
+ stringvalidator .ConflictsWith (
98
93
fwpath .MatchRoot ("source_dir" ),
99
94
fwpath .MatchRoot ("source_content" ),
100
95
fwpath .MatchRoot ("source_content_filename" ),
101
96
),
102
97
},
103
98
},
104
- "source_dir" : {
99
+ "source_dir" : schema. StringAttribute {
105
100
Description : "Package entire contents of this directory into the archive." ,
106
- Type : types .StringType ,
107
101
Optional : true ,
108
- Validators : []tfsdk. AttributeValidator {
109
- schemavalidator .ConflictsWith (
102
+ Validators : []validator. String {
103
+ stringvalidator .ConflictsWith (
110
104
fwpath .MatchRoot ("source_file" ),
111
105
fwpath .MatchRoot ("source_content" ),
112
106
fwpath .MatchRoot ("source_content_filename" ),
113
107
),
114
108
},
115
109
},
116
- "excludes" : {
110
+ "excludes" : schema. SetAttribute {
117
111
Description : "Specify files to ignore when reading the `source_dir`." ,
118
- Type : types.SetType {
119
- ElemType : types .StringType ,
120
- },
121
- Optional : true ,
122
- Validators : []tfsdk.AttributeValidator {
123
- schemavalidator .ConflictsWith (
112
+ ElementType : types .StringType ,
113
+ Optional : true ,
114
+ Validators : []validator.Set {
115
+ setvalidator .ConflictsWith (
124
116
fwpath .MatchRoot ("source_file" ),
125
117
fwpath .MatchRoot ("source_content" ),
126
118
fwpath .MatchRoot ("source_content_filename" ),
127
119
),
128
120
},
129
121
},
130
- "output_path" : {
122
+ "output_path" : schema. StringAttribute {
131
123
Description : "The output of the archive file." ,
132
- Type : types .StringType ,
133
124
Required : true ,
134
125
},
135
- "output_size" : {
126
+ "output_size" : schema. Int64Attribute {
136
127
Description : "The byte size of the output archive file." ,
137
- Type : types .Int64Type ,
138
128
Computed : true ,
139
129
},
140
- "output_sha" : {
130
+ "output_sha" : schema. StringAttribute {
141
131
Description : "The SHA1 checksum of output archive file." ,
142
- Type : types .StringType ,
143
132
Computed : true ,
144
133
},
145
- "output_base64sha256" : {
134
+ "output_base64sha256" : schema. StringAttribute {
146
135
Description : "The base64-encoded SHA256 checksum of output archive file." ,
147
- Type : types .StringType ,
148
136
Computed : true ,
149
137
},
150
- "output_md5" : {
138
+ "output_md5" : schema. StringAttribute {
151
139
Description : "The MD5 checksum of output archive file." ,
152
- Type : types .StringType ,
153
140
Computed : true ,
154
141
},
155
- "output_file_mode" : {
142
+ "output_file_mode" : schema. StringAttribute {
156
143
Description : "String that specifies the octal file mode for all archived files. For example: `\" 0666\" `. " +
157
144
"Setting this will ensure that cross platform usage of this module will not vary the modes of archived " +
158
145
"files (and ultimately checksums) resulting in more deterministic behavior." ,
159
- Type : types .StringType ,
160
146
Optional : true ,
161
147
},
162
148
},
163
- }, nil
149
+ }
164
150
}
165
151
166
152
func archive (ctx context.Context , model fileModel ) error {
0 commit comments