-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
arn_data_source_fw.go
112 lines (93 loc) · 2.94 KB
/
arn_data_source_fw.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
// Code generated by tools/tfsdk2fw/main.go. Manual editing is required.
package meta
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"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-plugin-log/tflog"
)
// TODO: Remove
var NewDataSourceARNType = newDataSourceARNType
func init() {
registerDataSourceTypeFactory("aws_arn", newDataSourceARNType)
}
// newDataSourceARNType instantiates a new DataSourceType for the aws_arn data source.
func newDataSourceARNType(ctx context.Context) (provider.DataSourceType, error) {
return &dataSourceARNType{}, nil
}
type dataSourceARNType struct{}
// GetSchema returns the schema for this data source.
func (t *dataSourceARNType) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) {
schema := tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"account": {
Type: types.StringType,
Computed: true,
},
"arn": {
Type: ARNType,
Required: true,
},
"id": {
Type: types.StringType,
Optional: true,
Computed: true,
},
"partition": {
Type: types.StringType,
Computed: true,
},
"region": {
Type: types.StringType,
Computed: true,
},
"resource": {
Type: types.StringType,
Computed: true,
},
"service": {
Type: types.StringType,
Computed: true,
},
},
}
return schema, nil
}
// NewDataSource instantiates a new DataSource of this DataSourceType.
func (t *dataSourceARNType) NewDataSource(ctx context.Context, provider provider.Provider) (datasource.DataSource, diag.Diagnostics) {
return &dataSourceARN{}, nil
}
type dataSourceARN struct{}
// Read is called when the provider must read data source values in order to update state.
// Config values should be read from the ReadRequest and new state values set on the ReadResponse.
func (d *dataSourceARN) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
tflog.Trace(ctx, "dataSourceARN.Read enter")
var config dataSourceARNData
response.Diagnostics.Append(request.Config.Get(ctx, &config)...)
if response.Diagnostics.HasError() {
return
}
state := config
arn := &state.ARN.Value
id := arn.String()
state.Account = &arn.AccountID
state.ID = &id
state.Partition = &arn.Partition
state.Region = &arn.Region
state.Resource = &arn.Resource
state.Service = &arn.Service
response.Diagnostics.Append(response.State.Set(ctx, &state)...)
}
// TODO: Generate this structure definition.
type dataSourceARNData struct {
Account *string `tfsdk:"account"`
ARN ARN `tfsdk:"arn"`
ID *string `tfsdk:"id"`
Partition *string `tfsdk:"partition"`
Region *string `tfsdk:"region"`
Resource *string `tfsdk:"resource"`
Service *string `tfsdk:"service"`
}