Skip to content

Commit

Permalink
Remove OneOf implementation for Build type (#518)
Browse files Browse the repository at this point in the history
* this generates the schema as expected

* generate SDKs

* remove string input handling from implementation
  • Loading branch information
guineveresaenger authored Mar 7, 2023
1 parent 83e176a commit aedffd8
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 71 deletions.
9 changes: 1 addition & 8 deletions provider/cmd/pulumi-resource-docker/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4436,14 +4436,7 @@
"type": "object",
"inputProperties": {
"build": {
"oneOf": [
{
"type": "string"
},
{
"$ref": "#/types/docker:index/dockerBuild:DockerBuild"
}
],
"$ref": "#/types/docker:index/dockerBuild:DockerBuild",
"description": "The Docker build context"
},
"imageName": {
Expand Down
7 changes: 0 additions & 7 deletions provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ func marshalBuildAndApplyDefaults(b resource.PropertyValue) (Build, error) {
build.Context = "."
return build, nil
}
if b.IsString() {
// use the filepath as context
build.Context = b.StringValue()
build.Dockerfile = defaultDockerfile
return build, nil
}

// read in the build type fields
buildObject := b.ObjectValue()
// Dockerfile
Expand Down
11 changes: 0 additions & 11 deletions provider/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ func TestMarshalBuildAndApplyDefaults(t *testing.T) {
assert.NoError(t, err)
})

t.Run("String input Build", func(t *testing.T) {
expected := Build{
Context: "/twilight/sparkle/bin",
Dockerfile: "Dockerfile",
}
input := resource.NewStringProperty("/twilight/sparkle/bin")
actual, err := marshalBuildAndApplyDefaults(input)
assert.Equal(t, expected, actual)
assert.NoError(t, err)
})

t.Run("Custom Dockerfile with default context", func(t *testing.T) {
expected := Build{
Context: ".",
Expand Down
9 changes: 1 addition & 8 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,7 @@ func Provider() tfbridge.ProviderInfo {
"build": {
Description: "The Docker build context",
TypeSpec: schema.TypeSpec{
OneOf: []schema.TypeSpec{
{
Type: "string",
},
{
Ref: "#/types/docker:index/dockerBuild:DockerBuild",
},
},
Ref: "#/types/docker:index/dockerBuild:DockerBuild",
},
},
"skipPush": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/dotnet/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public sealed class ImageArgs : global::Pulumi.ResourceArgs
/// The Docker build context
/// </summary>
[Input("build")]
public InputUnion<string, Inputs.DockerBuildArgs>? Build { get; set; }
public Input<Inputs.DockerBuildArgs>? Build { get; set; }

/// <summary>
/// The image name
Expand Down
7 changes: 5 additions & 2 deletions sdk/go/docker/image.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 147 additions & 0 deletions sdk/go/docker/pulumiTypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 4 additions & 25 deletions sdk/java/src/main/java/com/pulumi/docker/ImageArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.pulumi.docker;

import com.pulumi.core.Either;
import com.pulumi.core.Output;
import com.pulumi.core.annotations.Import;
import com.pulumi.core.internal.Codegen;
Expand All @@ -25,13 +24,13 @@ public final class ImageArgs extends com.pulumi.resources.ResourceArgs {
*
*/
@Import(name="build")
private @Nullable Output<Either<String,DockerBuildArgs>> build;
private @Nullable Output<DockerBuildArgs> build;

/**
* @return The Docker build context
*
*/
public Optional<Output<Either<String,DockerBuildArgs>>> build() {
public Optional<Output<DockerBuildArgs>> build() {
return Optional.ofNullable(this.build);
}

Expand Down Expand Up @@ -113,39 +112,19 @@ public Builder(ImageArgs defaults) {
* @return builder
*
*/
public Builder build(@Nullable Output<Either<String,DockerBuildArgs>> build) {
public Builder build(@Nullable Output<DockerBuildArgs> build) {
$.build = build;
return this;
}

/**
* @param build The Docker build context
*
* @return builder
*
*/
public Builder build(Either<String,DockerBuildArgs> build) {
return build(Output.of(build));
}

/**
* @param build The Docker build context
*
* @return builder
*
*/
public Builder build(String build) {
return build(Either.ofLeft(build));
}

/**
* @param build The Docker build context
*
* @return builder
*
*/
public Builder build(DockerBuildArgs build) {
return build(Either.ofRight(build));
return build(Output.of(build));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sdk/nodejs/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Image extends pulumi.CustomResource {
if ((!args || args.imageName === undefined) && !opts.urn) {
throw new Error("Missing required property 'imageName'");
}
resourceInputs["build"] = args ? args.build : undefined;
resourceInputs["build"] = args ? (args.build ? pulumi.output(args.build).apply(inputs.dockerBuildProvideDefaults) : undefined) : undefined;
resourceInputs["imageName"] = args ? args.imageName : undefined;
resourceInputs["registry"] = args ? args.registry : undefined;
resourceInputs["skipPush"] = (args ? args.skipPush : undefined) ?? false;
Expand All @@ -109,7 +109,7 @@ export interface ImageArgs {
/**
* The Docker build context
*/
build?: pulumi.Input<string | inputs.DockerBuild>;
build?: pulumi.Input<inputs.DockerBuild>;
/**
* The image name
*/
Expand Down
Loading

0 comments on commit aedffd8

Please sign in to comment.