forked from airbytehq/terraform-provider-airbyte
/
source_datadog_resource_sdk.go
executable file
·166 lines (158 loc) · 5.5 KB
/
source_datadog_resource_sdk.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
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package provider
import (
"github.com/ryan-pip/terraform-provider-airbyte/internal/sdk/pkg/models/shared"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func (r *SourceDatadogResourceModel) ToCreateSDKType() *shared.SourceDatadogCreateRequest {
apiKey := r.Configuration.APIKey.ValueString()
applicationKey := r.Configuration.ApplicationKey.ValueString()
endDate := new(string)
if !r.Configuration.EndDate.IsUnknown() && !r.Configuration.EndDate.IsNull() {
*endDate = r.Configuration.EndDate.ValueString()
} else {
endDate = nil
}
maxRecordsPerRequest := new(int64)
if !r.Configuration.MaxRecordsPerRequest.IsUnknown() && !r.Configuration.MaxRecordsPerRequest.IsNull() {
*maxRecordsPerRequest = r.Configuration.MaxRecordsPerRequest.ValueInt64()
} else {
maxRecordsPerRequest = nil
}
var queries []shared.SourceDatadogQueries = nil
for _, queriesItem := range r.Configuration.Queries {
dataSource := shared.SourceDatadogQueriesDataSource(queriesItem.DataSource.ValueString())
name := queriesItem.Name.ValueString()
query := queriesItem.Query.ValueString()
queries = append(queries, shared.SourceDatadogQueries{
DataSource: dataSource,
Name: name,
Query: query,
})
}
query1 := new(string)
if !r.Configuration.Query.IsUnknown() && !r.Configuration.Query.IsNull() {
*query1 = r.Configuration.Query.ValueString()
} else {
query1 = nil
}
site := new(shared.SourceDatadogSite)
if !r.Configuration.Site.IsUnknown() && !r.Configuration.Site.IsNull() {
*site = shared.SourceDatadogSite(r.Configuration.Site.ValueString())
} else {
site = nil
}
sourceType := shared.SourceDatadogDatadog(r.Configuration.SourceType.ValueString())
startDate := new(string)
if !r.Configuration.StartDate.IsUnknown() && !r.Configuration.StartDate.IsNull() {
*startDate = r.Configuration.StartDate.ValueString()
} else {
startDate = nil
}
configuration := shared.SourceDatadog{
APIKey: apiKey,
ApplicationKey: applicationKey,
EndDate: endDate,
MaxRecordsPerRequest: maxRecordsPerRequest,
Queries: queries,
Query: query1,
Site: site,
SourceType: sourceType,
StartDate: startDate,
}
name1 := r.Name.ValueString()
secretID := new(string)
if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
*secretID = r.SecretID.ValueString()
} else {
secretID = nil
}
workspaceID := r.WorkspaceID.ValueString()
out := shared.SourceDatadogCreateRequest{
Configuration: configuration,
Name: name1,
SecretID: secretID,
WorkspaceID: workspaceID,
}
return &out
}
func (r *SourceDatadogResourceModel) ToGetSDKType() *shared.SourceDatadogCreateRequest {
out := r.ToCreateSDKType()
return out
}
func (r *SourceDatadogResourceModel) ToUpdateSDKType() *shared.SourceDatadogPutRequest {
apiKey := r.Configuration.APIKey.ValueString()
applicationKey := r.Configuration.ApplicationKey.ValueString()
endDate := new(string)
if !r.Configuration.EndDate.IsUnknown() && !r.Configuration.EndDate.IsNull() {
*endDate = r.Configuration.EndDate.ValueString()
} else {
endDate = nil
}
maxRecordsPerRequest := new(int64)
if !r.Configuration.MaxRecordsPerRequest.IsUnknown() && !r.Configuration.MaxRecordsPerRequest.IsNull() {
*maxRecordsPerRequest = r.Configuration.MaxRecordsPerRequest.ValueInt64()
} else {
maxRecordsPerRequest = nil
}
var queries []shared.SourceDatadogUpdateQueries = nil
for _, queriesItem := range r.Configuration.Queries {
dataSource := shared.SourceDatadogUpdateQueriesDataSource(queriesItem.DataSource.ValueString())
name := queriesItem.Name.ValueString()
query := queriesItem.Query.ValueString()
queries = append(queries, shared.SourceDatadogUpdateQueries{
DataSource: dataSource,
Name: name,
Query: query,
})
}
query1 := new(string)
if !r.Configuration.Query.IsUnknown() && !r.Configuration.Query.IsNull() {
*query1 = r.Configuration.Query.ValueString()
} else {
query1 = nil
}
site := new(shared.SourceDatadogUpdateSite)
if !r.Configuration.Site.IsUnknown() && !r.Configuration.Site.IsNull() {
*site = shared.SourceDatadogUpdateSite(r.Configuration.Site.ValueString())
} else {
site = nil
}
startDate := new(string)
if !r.Configuration.StartDate.IsUnknown() && !r.Configuration.StartDate.IsNull() {
*startDate = r.Configuration.StartDate.ValueString()
} else {
startDate = nil
}
configuration := shared.SourceDatadogUpdate{
APIKey: apiKey,
ApplicationKey: applicationKey,
EndDate: endDate,
MaxRecordsPerRequest: maxRecordsPerRequest,
Queries: queries,
Query: query1,
Site: site,
StartDate: startDate,
}
name1 := r.Name.ValueString()
workspaceID := r.WorkspaceID.ValueString()
out := shared.SourceDatadogPutRequest{
Configuration: configuration,
Name: name1,
WorkspaceID: workspaceID,
}
return &out
}
func (r *SourceDatadogResourceModel) ToDeleteSDKType() *shared.SourceDatadogCreateRequest {
out := r.ToCreateSDKType()
return out
}
func (r *SourceDatadogResourceModel) RefreshFromGetResponse(resp *shared.SourceResponse) {
r.Name = types.StringValue(resp.Name)
r.SourceID = types.StringValue(resp.SourceID)
r.SourceType = types.StringValue(resp.SourceType)
r.WorkspaceID = types.StringValue(resp.WorkspaceID)
}
func (r *SourceDatadogResourceModel) RefreshFromCreateResponse(resp *shared.SourceResponse) {
r.RefreshFromGetResponse(resp)
}