/
provider.go
342 lines (324 loc) · 13.2 KB
/
provider.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
package fwprovider
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-provider-aws/internal/service/meta"
"github.com/hashicorp/terraform-provider-aws/names"
)
// New returns a new, initialized Terraform Plugin Framework-style provider instance.
// The provider instance is fully configured once the `Configure` method has been called.
func New(primary interface{ Meta() interface{} }) provider.Provider {
return &fwprovider{
Primary: primary,
}
}
type fwprovider struct {
Primary interface{ Meta() interface{} }
}
// GetSchema returns the schema for this provider's configuration.
func (p *fwprovider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {
var diags diag.Diagnostics
// This schema must match exactly the Terraform Protocol v5 (Terraform Plugin SDK v2) provider's schema.
schema := tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"access_key": {
Type: types.StringType,
Optional: true,
Description: "The access key for API operations. You can retrieve this\nfrom the 'Security & Credentials' section of the AWS console.",
},
"allowed_account_ids": {
Type: types.SetType{ElemType: types.StringType},
Optional: true,
},
"custom_ca_bundle": {
Type: types.StringType,
Optional: true,
Description: "File containing custom root and intermediate certificates. Can also be configured using the `AWS_CA_BUNDLE` environment variable. (Setting `ca_bundle` in the shared config file is not supported.)",
},
"ec2_metadata_service_endpoint": {
Type: types.StringType,
Optional: true,
Description: "Address of the EC2 metadata service endpoint to use. Can also be configured using the `AWS_EC2_METADATA_SERVICE_ENDPOINT` environment variable.",
},
"ec2_metadata_service_endpoint_mode": {
Type: types.StringType,
Optional: true,
Description: "Protocol to use with EC2 metadata service endpoint.Valid values are `IPv4` and `IPv6`. Can also be configured using the `AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE` environment variable.",
},
"forbidden_account_ids": {
Type: types.SetType{ElemType: types.StringType},
Optional: true,
},
"http_proxy": {
Type: types.StringType,
Optional: true,
Description: "The address of an HTTP proxy to use when accessing the AWS API. Can also be configured using the `HTTP_PROXY` or `HTTPS_PROXY` environment variables.",
},
"insecure": {
Type: types.BoolType,
Optional: true,
Description: "Explicitly allow the provider to perform \"insecure\" SSL requests. If omitted, default value is `false`",
},
"max_retries": {
Type: types.Int64Type,
Optional: true,
Description: "The maximum number of times an AWS API request is\nbeing executed. If the API request still fails, an error is\nthrown.",
},
"profile": {
Type: types.StringType,
Optional: true,
Description: "The profile for API operations. If not set, the default profile\ncreated with `aws configure` will be used.",
},
"region": {
Type: types.StringType,
Optional: true,
Description: "The region where AWS operations will take place. Examples\nare us-east-1, us-west-2, etc.", // lintignore:AWSAT003
},
"s3_force_path_style": {
Type: types.BoolType,
Optional: true,
Description: "Set this to true to enable the request to use path-style addressing,\ni.e., https://s3.amazonaws.com/BUCKET/KEY. By default, the S3 client will\nuse virtual hosted bucket addressing when possible\n(https://BUCKET.s3.amazonaws.com/KEY). Specific to the Amazon S3 service.",
DeprecationMessage: "Use s3_use_path_style instead.",
},
"s3_use_path_style": {
Type: types.BoolType,
Optional: true,
Description: "Set this to true to enable the request to use path-style addressing,\ni.e., https://s3.amazonaws.com/BUCKET/KEY. By default, the S3 client will\nuse virtual hosted bucket addressing when possible\n(https://BUCKET.s3.amazonaws.com/KEY). Specific to the Amazon S3 service.",
},
"secret_key": {
Type: types.StringType,
Optional: true,
Description: "The secret key for API operations. You can retrieve this\nfrom the 'Security & Credentials' section of the AWS console.",
},
"shared_config_files": {
Type: types.ListType{ElemType: types.StringType},
Optional: true,
Description: "List of paths to shared config files. If not set, defaults to [~/.aws/config].",
},
"shared_credentials_file": {
Type: types.StringType,
Optional: true,
Description: "The path to the shared credentials file. If not set, defaults to ~/.aws/credentials.",
DeprecationMessage: "Use shared_credentials_files instead.",
},
"shared_credentials_files": {
Type: types.ListType{ElemType: types.StringType},
Optional: true,
Description: "List of paths to shared credentials files. If not set, defaults to [~/.aws/credentials].",
},
"skip_credentials_validation": {
Type: types.BoolType,
Optional: true,
Description: "Skip the credentials validation via STS API. Used for AWS API implementations that do not have STS available/implemented.",
},
"skip_get_ec2_platforms": {
Type: types.BoolType,
Optional: true,
Description: "Skip getting the supported EC2 platforms. Used by users that don't have ec2:DescribeAccountAttributes permissions.",
},
"skip_metadata_api_check": {
Type: types.StringType,
Optional: true,
Description: "Skip the AWS Metadata API check. Used for AWS API implementations that do not have a metadata api endpoint.",
},
"skip_region_validation": {
Type: types.BoolType,
Optional: true,
Description: "Skip static validation of region name. Used by users of alternative AWS-like APIs or users w/ access to regions that are not public (yet).",
},
"skip_requesting_account_id": {
Type: types.BoolType,
Optional: true,
Description: "Skip requesting the account ID. Used for AWS API implementations that do not have IAM/STS API and/or metadata API.",
},
"sts_region": {
Type: types.StringType,
Optional: true,
Description: "The region where AWS STS operations will take place. Examples\nare us-east-1 and us-west-2.", // lintignore:AWSAT003
},
"token": {
Type: types.StringType,
Optional: true,
Description: "session token. A session token is only required if you are\nusing temporary security credentials.",
},
"use_dualstack_endpoint": {
Type: types.BoolType,
Optional: true,
Description: "Resolve an endpoint with DualStack capability",
},
"use_fips_endpoint": {
Type: types.BoolType,
Optional: true,
Description: "Resolve an endpoint with FIPS capability",
},
},
Blocks: map[string]tfsdk.Block{
"assume_role": {
Attributes: map[string]tfsdk.Attribute{
"duration": {
Type: DurationType,
Optional: true,
Description: "The duration, between 15 minutes and 12 hours, of the role session. Valid time units are ns, us (or µs), ms, s, h, or m.",
},
"duration_seconds": {
Type: types.Int64Type,
Optional: true,
Description: "The duration, in seconds, of the role session.",
DeprecationMessage: "Use assume_role.duration instead",
},
"external_id": {
Type: types.StringType,
Optional: true,
Description: "A unique identifier that might be required when you assume a role in another account.",
},
"policy": {
Type: types.StringType,
Optional: true,
Description: "IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.",
},
"policy_arns": {
Type: types.SetType{ElemType: types.StringType},
Optional: true,
Description: "Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.",
},
"role_arn": {
Type: types.StringType,
Optional: true,
Description: "Amazon Resource Name (ARN) of an IAM Role to assume prior to making API calls.",
},
"session_name": {
Type: types.StringType,
Optional: true,
Description: "An identifier for the assumed role session.",
},
"tags": {
Type: types.MapType{ElemType: types.StringType},
Optional: true,
Description: "Assume role session tags.",
},
"transitive_tag_keys": {
Type: types.SetType{ElemType: types.StringType},
Optional: true,
Description: "Assume role session tag keys to pass to any subsequent sessions.",
},
},
NestingMode: tfsdk.BlockNestingModeList,
MaxItems: 1,
},
"assume_role_with_web_identity": {
Attributes: map[string]tfsdk.Attribute{
"duration": {
Type: DurationType,
Optional: true,
Description: "The duration, between 15 minutes and 12 hours, of the role session. Valid time units are ns, us (or µs), ms, s, h, or m.",
},
"policy": {
Type: types.StringType,
Optional: true,
Description: "IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.",
},
"policy_arns": {
Type: types.SetType{ElemType: types.StringType},
Optional: true,
Description: "Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.",
},
"role_arn": {
Type: types.StringType,
Optional: true,
Description: "Amazon Resource Name (ARN) of an IAM Role to assume prior to making API calls.",
},
"session_name": {
Type: types.StringType,
Optional: true,
Description: "An identifier for the assumed role session.",
},
"web_identity_token": {
Type: types.StringType,
Optional: true,
},
"web_identity_token_file": {
Type: types.StringType,
Optional: true,
},
},
NestingMode: tfsdk.BlockNestingModeList,
MaxItems: 1,
},
"default_tags": {
Attributes: map[string]tfsdk.Attribute{
"tags": {
Type: types.MapType{ElemType: types.StringType},
Optional: true,
Description: "Resource tags to default across all resources",
},
},
NestingMode: tfsdk.BlockNestingModeList,
MaxItems: 1,
Description: "Configuration block with settings to default resource tags across all resources.",
},
"endpoints": endpointsBlock(),
"ignore_tags": {
Attributes: map[string]tfsdk.Attribute{
"key_prefixes": {
Type: types.SetType{ElemType: types.StringType},
Optional: true,
Description: "Resource tag key prefixes to ignore across all resources.",
},
"keys": {
Type: types.SetType{ElemType: types.StringType},
Optional: true,
Description: "Resource tag keys to ignore across all resources.",
},
},
NestingMode: tfsdk.BlockNestingModeList,
MaxItems: 1,
Description: "Configuration block with settings to ignore resource tags across all resources.",
},
},
}
return schema, diags
}
// Configure is called at the beginning of the provider lifecycle, when
// Terraform sends to the provider the values the user specified in the
// provider configuration block.
func (p *fwprovider) Configure(ctx context.Context, request provider.ConfigureRequest, response *provider.ConfigureResponse) {
// Provider's parsed configuration (its instance state) is available through the primary provider's Meta() method.
}
// GetResources returns a mapping of resource names to type
// implementations.
func (p *fwprovider) GetResources(ctx context.Context) (map[string]provider.ResourceType, diag.Diagnostics) {
var diags diag.Diagnostics
resources := make(map[string]provider.ResourceType)
return resources, diags
}
// GetDataSources returns a mapping of data source name to types
// implementations.
func (p *fwprovider) GetDataSources(ctx context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) {
var diags diag.Diagnostics
dataSources := make(map[string]provider.DataSourceType)
// TODO: This should be done via service-level self-registration and initializatin in the primary provider.
t, err := meta.NewDataSourceARNType(ctx)
if err != nil {
diags.AddError("UhOh", err.Error())
return nil, diags
}
dataSources["aws_arn"] = t
return dataSources, diags
}
func endpointsBlock() tfsdk.Block {
endpointsAttributes := make(map[string]tfsdk.Attribute)
for _, serviceKey := range names.Aliases() {
endpointsAttributes[serviceKey] = tfsdk.Attribute{
Type: types.StringType,
Optional: true,
Description: "Use this to override the default service endpoint URL",
}
}
return tfsdk.Block{
Attributes: endpointsAttributes,
NestingMode: tfsdk.BlockNestingModeSet,
}
}