// Copyright 2016-2023, 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 provider import ( "math/rand" "time" p "github.com/pulumi/pulumi-go-provider" "github.com/pulumi/pulumi-go-provider/infer" "github.com/pulumi/pulumi-go-provider/middleware/schema" "github.com/pulumi/pulumi-java/pkg/codegen/java" csgen "github.com/pulumi/pulumi/pkg/v3/codegen/dotnet" gogen "github.com/pulumi/pulumi/pkg/v3/codegen/go" tsgen "github.com/pulumi/pulumi/pkg/v3/codegen/nodejs" pygen "github.com/pulumi/pulumi/pkg/v3/codegen/python" "github.com/pulumi/pulumi/sdk/v3/go/common/tokens" ) // Version is initialized by the Go linker to contain the semver of this build. var Version string const Name string = "dockerbuild" // Needs to match $PACK in Makefile. func Provider() p.Provider { // We tell the provider what resources it needs to support. // In this case, a single custom resource. return infer.Provider(infer.Options{ Metadata: schema.Metadata{ DisplayName: "dockerbuild", LanguageMap: map[string]any{ "go": gogen.GoPackageInfo{ // GenerateResourceContainerTypes: true, Generics: gogen.GenericsSettingGenericsOnly, PackageImportAliases: map[string]string{ "github.com/pulumi/pulumi-dockerbuild/sdk/go/dockerbuild": "dockerbuild", }, ImportBasePath: "github.com/pulumi/pulumi-dockerbuild/sdk/go/dockerbuild", }, "csharp": csgen.CSharpPackageInfo{ PackageReferences: map[string]string{ "Pulumi": "3.*", }, }, "java": java.PackageInfo{ BuildFiles: "gradle", GradleNexusPublishPluginVersion: "1.1.0", Dependencies: map[string]string{ "com.pulumi:pulumi": "0.9.9", "com.google.code.gson:gson": "2.8.9", "com.google.code.findbugs:jsr305": "3.0.2", }, }, "nodejs": tsgen.NodePackageInfo{ Dependencies: map[string]string{ "@pulumi/pulumi": "^3.0.0", }, }, "python": pygen.PackageInfo{ PyProject: struct { Enabled bool `json:"enabled,omitempty"` }{Enabled: true}, Requires: map[string]string{ "pulumi": ">=3.0.0,<4.0.0", }, }, }, Description: "Description", Keywords: []string{"keywords"}, Homepage: "pulumi.com", Publisher: "pulumi", Repository: "https://github.com/pulumi/pulumi-dockerbuild", PluginDownloadURL: "github.com/pulumi/pulumi-dockerbuild", }, Resources: []infer.InferredResource{ infer.Resource[Random, RandomArgs, RandomState](), }, ModuleMap: map[tokens.ModuleName]tokens.ModuleName{ "provider": "index", }, }) } // Each resource has a controlling struct. // Resource behavior is determined by implementing methods on the controlling struct. // The `Create` method is mandatory, but other methods are optional. // - Check: Remap inputs before they are typed. // - Diff: Change how instances of a resource are compared. // - Update: Mutate a resource in place. // - Read: Get the state of a resource from the backing provider. // - Delete: Custom logic when the resource is deleted. // - Annotate: Describe fields and set defaults for a resource. // - WireDependencies: Control how outputs and secrets flows through values. type Random struct{} // Each resource has an input struct, defining what arguments it accepts. type RandomArgs struct { // Fields projected into Pulumi must be public and hava a `pulumi:"..."` tag. // The pulumi tag doesn't need to match the field name, but it's generally a // good idea. Length int `pulumi:"length"` } // Each resource has a state, describing the fields that exist on the created resource. type RandomState struct { // It is generally a good idea to embed args in outputs, but it isn't strictly necessary. RandomArgs // Here we define a required output called result. Result string `pulumi:"result" provider:"output"` } // All resources must implement Create at a minimum. func (Random) Create(ctx p.Context, name string, input RandomArgs, preview bool) (string, RandomState, error) { state := RandomState{RandomArgs: input} if preview { return name, state, nil } state.Result = makeRandom(input.Length) return name, state, nil } func makeRandom(length int) string { seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint: gosec charset := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") result := make([]rune, length) for i := range result { result[i] = charset[seededRand.Intn(len(charset))] } return string(result) }