-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsingle_nested.go
More file actions
145 lines (111 loc) · 4.25 KB
/
single_nested.go
File metadata and controls
145 lines (111 loc) · 4.25 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
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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package attrmapper
import (
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util"
"github.com/hashicorp/terraform-plugin-codegen-spec/datasource"
"github.com/hashicorp/terraform-plugin-codegen-spec/provider"
"github.com/hashicorp/terraform-plugin-codegen-spec/resource"
"github.com/hashicorp/terraform-plugin-codegen-spec/schema"
)
type ResourceSingleNestedAttribute struct {
resource.SingleNestedAttribute
Name string
Attributes ResourceAttributes
}
func (a *ResourceSingleNestedAttribute) GetName() string {
return a.Name
}
func (a *ResourceSingleNestedAttribute) Merge(mergeAttribute ResourceAttribute) (ResourceAttribute, error) {
singleNestedAttribute, ok := mergeAttribute.(*ResourceSingleNestedAttribute)
// TODO: return error if types don't match?
if !ok {
return a, nil
}
if a.Description == nil || *a.Description == "" {
a.Description = singleNestedAttribute.Description
}
a.Attributes, _ = a.Attributes.Merge(singleNestedAttribute.Attributes)
return a, nil
}
func (a *ResourceSingleNestedAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) {
a.Description = &override.Description
return a, nil
}
func (a *ResourceSingleNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (ResourceAttribute, error) {
var err error
a.Attributes, err = a.Attributes.ApplyOverride(path, override)
return a, err
}
func (a *ResourceSingleNestedAttribute) NestedMerge(path []string, attribute ResourceAttribute, intermediateComputability schema.ComputedOptionalRequired) (ResourceAttribute, error) {
var err error
a.Attributes, err = a.Attributes.MergeAttribute(path, attribute, intermediateComputability)
if err == nil {
a.ComputedOptionalRequired = intermediateComputability
}
return a, err
}
func (a *ResourceSingleNestedAttribute) ToSpec() resource.Attribute {
a.SingleNestedAttribute.Attributes = a.Attributes.ToSpec()
return resource.Attribute{
Name: util.TerraformIdentifier(a.Name),
SingleNested: &a.SingleNestedAttribute,
}
}
type DataSourceSingleNestedAttribute struct {
datasource.SingleNestedAttribute
Name string
Attributes DataSourceAttributes
}
func (a *DataSourceSingleNestedAttribute) GetName() string {
return a.Name
}
func (a *DataSourceSingleNestedAttribute) Merge(mergeAttribute DataSourceAttribute) (DataSourceAttribute, error) {
singleNestedAttribute, ok := mergeAttribute.(*DataSourceSingleNestedAttribute)
// TODO: return error if types don't match?
if !ok {
return a, nil
}
if a.Description == nil || *a.Description == "" {
a.Description = singleNestedAttribute.Description
}
a.Attributes, _ = a.Attributes.Merge(singleNestedAttribute.Attributes)
return a, nil
}
func (a *DataSourceSingleNestedAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) {
a.Description = &override.Description
return a, nil
}
func (a *DataSourceSingleNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (DataSourceAttribute, error) {
var err error
a.Attributes, err = a.Attributes.ApplyOverride(path, override)
return a, err
}
func (a *DataSourceSingleNestedAttribute) NestedMerge(path []string, attribute DataSourceAttribute, intermediateComputability schema.ComputedOptionalRequired) (DataSourceAttribute, error) {
var err error
a.Attributes, err = a.Attributes.MergeAttribute(path, attribute, intermediateComputability)
if err == nil {
a.ComputedOptionalRequired = intermediateComputability
}
return a, err
}
func (a *DataSourceSingleNestedAttribute) ToSpec() datasource.Attribute {
a.SingleNestedAttribute.Attributes = a.Attributes.ToSpec()
return datasource.Attribute{
Name: util.TerraformIdentifier(a.Name),
SingleNested: &a.SingleNestedAttribute,
}
}
type ProviderSingleNestedAttribute struct {
provider.SingleNestedAttribute
Name string
Attributes ProviderAttributes
}
func (a *ProviderSingleNestedAttribute) ToSpec() provider.Attribute {
a.SingleNestedAttribute.Attributes = a.Attributes.ToSpec()
return provider.Attribute{
Name: util.TerraformIdentifier(a.Name),
SingleNested: &a.SingleNestedAttribute,
}
}