generated from pulumi/pulumi-provider-boilerplate
/
commandController.go
78 lines (70 loc) · 2.49 KB
/
commandController.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
// Copyright 2016-2022, 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 remote
import (
p "github.com/pulumi/pulumi-go-provider"
"github.com/pulumi/pulumi-go-provider/infer"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
)
// These are not required. They indicate to Go that Command implements the following interfaces.
// If the function signature doesn't match or isn't implemented, we get nice compile time errors in this file.
var _ = (infer.CustomResource[CommandInputs, CommandOutputs])((*Command)(nil))
var _ = (infer.CustomUpdate[CommandInputs, CommandOutputs])((*Command)(nil))
var _ = (infer.CustomDelete[CommandOutputs])((*Command)(nil))
// This is the Create method. This will be run on every Command resource creation.
func (*Command) Create(ctx p.Context, name string, input CommandInputs, preview bool) (string, CommandOutputs, error) {
state := CommandOutputs{CommandInputs: input}
var err error
id, err := resource.NewUniqueHex(name, 8, 0)
if err != nil {
return "", state, err
}
if preview {
return id, state, nil
}
if state.Create == nil {
return id, state, nil
}
cmd := ""
if state.Create != nil {
cmd = *state.Create
}
if !preview {
err = state.run(ctx, cmd, input.Logging)
}
return id, state, err
}
// The Update method will be run on every update.
func (*Command) Update(ctx p.Context, id string, olds CommandOutputs, news CommandInputs, preview bool) (CommandOutputs, error) {
state := CommandOutputs{CommandInputs: news, BaseOutputs: olds.BaseOutputs}
if preview {
return state, nil
}
var err error
if !preview {
if news.Update != nil {
err = state.run(ctx, *news.Update, news.Logging)
} else if news.Create != nil {
err = state.run(ctx, *news.Create, news.Logging)
}
}
return state, err
}
// The Delete method will run when the resource is deleted.
func (*Command) Delete(ctx p.Context, id string, props CommandOutputs) error {
if props.Delete == nil {
return nil
}
return props.run(ctx, *props.Delete, props.Logging)
}