6
6
"os"
7
7
"path"
8
8
9
+ "github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator"
9
10
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
10
11
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
11
12
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -27,26 +28,31 @@ func NewArchiveFileResource() resource.Resource {
27
28
28
29
type archiveFileResource struct {}
29
30
31
+ func (d * archiveFileResource ) ConfigValidators (context.Context ) []resource.ConfigValidator {
32
+ return []resource.ConfigValidator {
33
+ resourcevalidator .AtLeastOneOf (
34
+ fwpath .MatchRoot ("source" ),
35
+ fwpath .MatchRoot ("source_content_filename" ),
36
+ fwpath .MatchRoot ("source_file" ),
37
+ fwpath .MatchRoot ("source_dir" ),
38
+ ),
39
+ }
40
+ }
41
+
30
42
func (d * archiveFileResource ) Schema (ctx context.Context , req resource.SchemaRequest , resp * resource.SchemaResponse ) {
31
43
resp .Schema = schema.Schema {
32
44
Description : `**NOTE**: This resource is deprecated, use data source instead.` ,
33
45
DeprecationMessage : `**NOTE**: This resource is deprecated, use data source instead.` ,
34
46
Blocks : map [string ]schema.Block {
35
47
"source" : schema.SetNestedBlock {
36
- Description : "Specifies attributes of a single source file to include into the archive." ,
48
+ Description : "Specifies attributes of a single source file to include into the archive. " +
49
+ "One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, " +
50
+ "or `source_dir` must be specified." ,
37
51
NestedObject : schema.NestedBlockObject {
38
52
Attributes : map [string ]schema.Attribute {
39
53
"content" : schema.StringAttribute {
40
54
Description : "Add this content to the archive with `filename` as the filename." ,
41
55
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
56
PlanModifiers : []planmodifier.String {
51
57
stringplanmodifier .RequiresReplace (),
52
58
},
@@ -60,6 +66,14 @@ func (d *archiveFileResource) Schema(ctx context.Context, req resource.SchemaReq
60
66
},
61
67
},
62
68
},
69
+ Validators : []validator.Set {
70
+ setvalidator .ConflictsWith (
71
+ fwpath .MatchRoot ("source_file" ),
72
+ fwpath .MatchRoot ("source_dir" ),
73
+ fwpath .MatchRoot ("source_content" ),
74
+ fwpath .MatchRoot ("source_content_filename" ),
75
+ ),
76
+ },
63
77
},
64
78
},
65
79
Attributes : map [string ]schema.Attribute {
@@ -75,8 +89,10 @@ func (d *archiveFileResource) Schema(ctx context.Context, req resource.SchemaReq
75
89
},
76
90
},
77
91
"source_content" : schema.StringAttribute {
78
- Description : "Add only this content to the archive with `source_content_filename` as the filename." ,
79
- Optional : true ,
92
+ Description : "Add only this content to the archive with `source_content_filename` as the filename. " +
93
+ "One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, " +
94
+ "or `source_dir` must be specified." ,
95
+ Optional : true ,
80
96
Validators : []validator.String {
81
97
stringvalidator .ConflictsWith (
82
98
fwpath .MatchRoot ("source_file" ),
@@ -88,8 +104,10 @@ func (d *archiveFileResource) Schema(ctx context.Context, req resource.SchemaReq
88
104
},
89
105
},
90
106
"source_content_filename" : schema.StringAttribute {
91
- Description : "Set this as the filename when using `source_content`." ,
92
- Optional : true ,
107
+ Description : "Set this as the filename when using `source_content`. " +
108
+ "One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, " +
109
+ "or `source_dir` must be specified." ,
110
+ Optional : true ,
93
111
Validators : []validator.String {
94
112
stringvalidator .ConflictsWith (
95
113
fwpath .MatchRoot ("source_file" ),
@@ -101,8 +119,10 @@ func (d *archiveFileResource) Schema(ctx context.Context, req resource.SchemaReq
101
119
},
102
120
},
103
121
"source_file" : schema.StringAttribute {
104
- Description : "Package this file into the archive." ,
105
- Optional : true ,
122
+ Description : "Package this file into the archive. " +
123
+ "One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, " +
124
+ "or `source_dir` must be specified." ,
125
+ Optional : true ,
106
126
Validators : []validator.String {
107
127
stringvalidator .ConflictsWith (
108
128
fwpath .MatchRoot ("source_dir" ),
@@ -115,8 +135,10 @@ func (d *archiveFileResource) Schema(ctx context.Context, req resource.SchemaReq
115
135
},
116
136
},
117
137
"source_dir" : schema.StringAttribute {
118
- Description : "Package entire contents of this directory into the archive." ,
119
- Optional : true ,
138
+ Description : "Package entire contents of this directory into the archive. " +
139
+ "One and only one of `source`, `source_content_filename` (with `source_content`), `source_file`, " +
140
+ "or `source_dir` must be specified." ,
141
+ Optional : true ,
120
142
Validators : []validator.String {
121
143
stringvalidator .ConflictsWith (
122
144
fwpath .MatchRoot ("source_file" ),
0 commit comments