/
provider.go
123 lines (108 loc) · 4.41 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
// Package property contains implementation for Property Provisioning module used to manage properties
package property
import (
"bytes"
"encoding/json"
"fmt"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v8/pkg/hapi"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v8/pkg/papi"
"github.com/akamai/terraform-provider-akamai/v6/pkg/common/str"
"github.com/akamai/terraform-provider-akamai/v6/pkg/meta"
"github.com/akamai/terraform-provider-akamai/v6/pkg/subprovider"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
type (
// Subprovider gathers property resources and data sources
Subprovider struct{}
)
var (
_ subprovider.Subprovider = &Subprovider{}
)
var (
client papi.PAPI
hapiClient hapi.HAPI
)
// NewSubprovider returns a new property subprovider
func NewSubprovider() *Subprovider {
return &Subprovider{}
}
// Client returns the PAPI interface
func Client(meta meta.Meta) papi.PAPI {
if client != nil {
return client
}
return papi.Client(meta.Session())
}
// HapiClient returns the HAPI interface
func HapiClient(meta meta.Meta) hapi.HAPI {
if hapiClient != nil {
return hapiClient
}
return hapi.Client(meta.Session())
}
// SDKResources returns the property resources implemented using terraform-plugin-sdk
func (p *Subprovider) SDKResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"akamai_cp_code": resourceCPCode(),
"akamai_edge_hostname": resourceSecureEdgeHostName(),
"akamai_property": resourceProperty(),
"akamai_property_activation": resourcePropertyActivation(),
"akamai_property_include": resourcePropertyInclude(),
"akamai_property_include_activation": resourcePropertyIncludeActivation(),
}
}
// SDKDataSources returns the property data sources implemented using terraform-plugin-sdk
func (p *Subprovider) SDKDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"akamai_contract": dataSourcePropertyContract(),
"akamai_contracts": dataSourceContracts(),
"akamai_cp_code": dataSourceCPCode(),
"akamai_group": dataSourcePropertyGroup(),
"akamai_groups": dataSourcePropertyMultipleGroups(),
"akamai_properties": dataSourceProperties(),
"akamai_properties_search": dataSourcePropertiesSearch(),
"akamai_property": dataSourceProperty(),
"akamai_property_activation": dataSourcePropertyActivation(),
"akamai_property_hostnames": dataSourcePropertyHostnames(),
"akamai_property_include_activation": dataSourcePropertyIncludeActivation(),
"akamai_property_include_parents": dataSourcePropertyIncludeParents(),
"akamai_property_include_rules": dataSourcePropertyIncludeRules(),
"akamai_property_includes": dataSourcePropertyIncludes(),
"akamai_property_products": dataSourcePropertyProducts(),
"akamai_property_rule_formats": dataSourcePropertyRuleFormats(),
"akamai_property_rules": dataSourcePropertyRules(),
"akamai_property_rules_builder": dataSourcePropertyRulesBuilder(),
"akamai_property_rules_template": dataSourcePropertyRulesTemplate(),
}
}
// FrameworkResources returns the property resources implemented using terraform-plugin-framework
func (p *Subprovider) FrameworkResources() []func() resource.Resource {
return []func() resource.Resource{
NewBootstrapResource,
}
}
// FrameworkDataSources returns the property data sources implemented using terraform-plugin-framework
func (p *Subprovider) FrameworkDataSources() []func() datasource.DataSource {
return []func() datasource.DataSource{
NewIncludeDataSource,
}
}
// compactJSON converts a JSON-encoded byte slice to a compact form (so our JSON fixtures can be readable)
func compactJSON(encoded []byte) string {
buf := bytes.Buffer{}
if err := json.Compact(&buf, encoded); err != nil {
panic(fmt.Sprintf("%s: %s", err, string(encoded)))
}
return buf.String()
}
// addPrefixToState returns a function that ensures string values are prefixed correctly
func addPrefixToState(prefix string) schema.SchemaStateFunc {
return func(given interface{}) string {
if given.(string) == "" {
return ""
}
return str.AddPrefix(given.(string), prefix)
}
}