-
Notifications
You must be signed in to change notification settings - Fork 2
/
resources.go
251 lines (231 loc) · 8.05 KB
/
resources.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
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pagerduty
import (
"bytes"
"context"
"fmt"
"path/filepath"
"unicode"
// embed is used to store bridge-metadata.json in the compiled binary
_ "embed"
// tzdata is used to ensure the provider works when deployed to OS-es that do not have it
_ "time/tzdata"
"github.com/PagerDuty/terraform-provider-pagerduty/v3/pagerduty"
pagerdutyplugin "github.com/PagerDuty/terraform-provider-pagerduty/v3/pagerdutyplugin"
pftfbridge "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
tfbridgetokens "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens"
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/pulumi/pulumi-pagerduty/provider/v4/pkg/version"
)
// all of the token components used below.
const (
// packages:
mainPkg = "pagerduty"
// modules:
mainMod = "index" // the y module
)
// makeMember manufactures a type token for the package and the given module and type.
func makeMember(mod string, mem string) tokens.ModuleMember {
return tokens.ModuleMember(mainPkg + ":" + mod + ":" + mem)
}
// makeType manufactures a type token for the package and the given module and type.
func makeType(mod string, typ string) tokens.Type {
return tokens.Type(makeMember(mod, typ))
}
// makeResource manufactures a standard resource token given a module and resource name. It
// automatically uses the main package and names the file by simply lower casing the resource's
// first character.
func makeResource(mod string, res string) tokens.Type {
fn := string(unicode.ToLower(rune(res[0]))) + res[1:]
return makeType(mod+"/"+fn, res)
}
// managedByPulumi is a default used for some managed resources, in the absence of something more meaningful.
var managedByPulumi = &tfbridge.DefaultInfo{Value: "Managed by Pulumi"}
// Provider returns additional overlaid schema and metadata associated with the provider..
func Provider() tfbridge.ProviderInfo {
// Instantiate the Terraform provider
sdkProv := shimv2.NewProvider(pagerduty.Provider(pagerduty.IsMuxed))
p := pftfbridge.MuxShimWithDisjointgPF(context.Background(), sdkProv, pagerdutyplugin.New())
// Create a Pulumi provider mapping
prov := tfbridge.ProviderInfo{
P: p,
Name: "pagerduty",
Description: "A Pulumi package for creating and managing pagerduty cloud resources.",
Keywords: []string{"pulumi", "pagerduty"},
License: "Apache-2.0",
Homepage: "https://pulumi.io",
GitHubOrg: "PagerDuty",
Repository: "https://github.com/pulumi/pulumi-pagerduty",
Version: version.Version,
DocRules: &tfbridge.DocRuleInfo{EditRules: docEditRules},
Config: map[string]*tfbridge.SchemaInfo{
"skip_credentials_validation": {
Type: "boolean",
Default: &tfbridge.DefaultInfo{
Value: false,
},
},
},
UpstreamRepoPath: "./upstream",
Resources: map[string]*tfbridge.ResourceInfo{
"pagerduty_business_service": {
Tok: makeResource(mainMod, "BusinessService"),
Fields: map[string]*tfbridge.SchemaInfo{
"description": {
Default: managedByPulumi,
},
},
},
"pagerduty_escalation_policy": {
Tok: makeResource(mainMod, "EscalationPolicy"),
Fields: map[string]*tfbridge.SchemaInfo{
"description": {
Default: managedByPulumi,
},
},
},
"pagerduty_extension_servicenow": {Tok: makeResource(mainMod, "ExtensionServiceNow")},
"pagerduty_maintenance_window": {
Tok: makeResource(mainMod, "MaintenanceWindow"),
Fields: map[string]*tfbridge.SchemaInfo{
"description": {
Default: managedByPulumi,
},
},
},
"pagerduty_schedule": {
Tok: makeResource(mainMod, "Schedule"),
Fields: map[string]*tfbridge.SchemaInfo{
"description": {
Default: managedByPulumi,
},
},
},
"pagerduty_service": {
Tok: makeResource(mainMod, "Service"),
Fields: map[string]*tfbridge.SchemaInfo{
"description": {
Default: managedByPulumi,
},
},
},
"pagerduty_team": {
Tok: makeResource(mainMod, "Team"),
Fields: map[string]*tfbridge.SchemaInfo{
"description": {
Default: managedByPulumi,
},
},
},
"pagerduty_user": {
Tok: makeResource(mainMod, "User"),
Fields: map[string]*tfbridge.SchemaInfo{
"description": {
Default: managedByPulumi,
},
},
},
"pagerduty_response_play": {
Tok: makeResource(mainMod, "ResponsePlay"),
Fields: map[string]*tfbridge.SchemaInfo{
"description": {
Default: managedByPulumi,
},
},
},
},
DataSources: map[string]*tfbridge.DataSourceInfo{
"pagerduty_event_orchestration": {
Tok: tfbridge.MakeDataSource("pagerduty", mainMod, "getEventOrchestration"),
Fields: map[string]*tfbridge.SchemaInfo{
"integration": {
Name: "integrationDetail",
},
},
},
},
JavaScript: &tfbridge.JavaScriptInfo{
// List any npm dependencies and their versions
Dependencies: map[string]string{
"@pulumi/pulumi": "^3.0.0",
},
DevDependencies: map[string]string{
"@types/node": "^10.0.0", // so we can access strongly typed node definitions.
"@types/mime": "^2.0.0",
},
RespectSchemaVersion: true,
},
Golang: &tfbridge.GolangInfo{
ImportBasePath: filepath.Join(
fmt.Sprintf("github.com/pulumi/pulumi-%[1]s/sdk/", mainPkg),
tfbridge.GetModuleMajorVersion(version.Version),
"go",
mainPkg,
),
GenerateResourceContainerTypes: true,
RespectSchemaVersion: true,
},
Python: (func() *tfbridge.PythonInfo {
i := &tfbridge.PythonInfo{
RespectSchemaVersion: true,
Requires: map[string]string{
"pulumi": ">=3.0.0,<4.0.0",
},
}
i.PyProject.Enabled = true
return i
})(),
CSharp: &tfbridge.CSharpInfo{
RespectSchemaVersion: true,
PackageReferences: map[string]string{
"Pulumi": "3.*",
},
}, MetadataInfo: tfbridge.NewProviderMetadata(metadata),
}
prov.MustComputeTokens(tfbridgetokens.SingleModule("pagerduty_",
mainMod, tfbridgetokens.MakeStandard(mainPkg)))
prov.MustApplyAutoAliases()
prov.SetAutonaming(255, "-")
return prov
}
func docEditRules(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit {
return append(defaults, tfbridge.DocsEdit{
Path: "service.html.markdown",
Edit: func(_ string, content []byte) ([]byte, error) {
content = bytes.Replace(content,
[]byte("You may specify one optional `incident_urgency_rule` block configuring what urgencies to "+
"use.\nYour PagerDuty account must have the `urgencies` ability to assign an incident urgency "+
"rule.\nThe block contains the following arguments:"),
[]byte("The `incident_urgency_rule` block contains the following arguments:"),
1)
content = bytes.Replace(content,
[]byte("When using `type = \"use_support_hours\"` in `incident_urgency_rule` you must specify "+
"exactly one (otherwise optional) `support_hours` block.\nYour PagerDuty account must have the "+
"`service_support_hours` ability to assign support hours."),
[]byte("The `support_hours` block contains the following arguments:"),
1)
content = bytes.Replace(content,
[]byte("A `scheduled_actions` block is required when using `type = \"use_support_hours\"` in "+
"`incident_urgency_rule`.\n\nThe block contains the following arguments:"),
[]byte("The `scheduled_actions` block contains the following arguments:"),
1)
return content, nil
},
})
}
//go:embed cmd/pulumi-resource-pagerduty/bridge-metadata.json
var metadata []byte