pulumi / pulumi-java

Java support for Pulumi
Apache License 2.0
64 stars 19 forks source link

Incorrect Java Code Example in Registry for aws.iam.GroupMembership resource #1340

Open toriancrane opened 3 months ago

toriancrane commented 3 months ago

What happened?

I tried to deploy the Java example on this page and received the following error:

image

Example

Deploy the Java example on this page

Output of pulumi about

N/A

Additional context

The issue seems to be that we need to create a single output that is a List containing both outputs. Here is a version of this resource that works (courtesy of @cnunciato):

package myproject;

import com.pulumi.Pulumi;
import com.pulumi.aws.iam.User;
import com.pulumi.aws.iam.UserArgs;
import com.pulumi.aws.iam.Group;
import com.pulumi.aws.iam.GroupArgs;
import com.pulumi.aws.iam.GroupPolicy;
import com.pulumi.aws.iam.GroupPolicyArgs;
import com.pulumi.aws.iam.GroupMembership;
import com.pulumi.aws.iam.GroupMembershipArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import com.pulumi.core.Output;
import java.util.List;

public class App {
    public static void main(String[] args) {
        Pulumi.run(ctx -> {

            var jane = new User("jane", UserArgs.builder().build());
            var mary = new User("mary", UserArgs.builder().build());

            // Create a single output from the two other outputs.
            var userIds = Output.all(jane.id(), mary.id()).applyValue(ids -> List.of(ids.get(0), ids.get(1)));

            // Define a group and assign a policy for it.
            var devs = new Group("devs", GroupArgs.builder()
                .path("/users/")
                .build());

            new GroupPolicy("my_developer_policy", GroupPolicyArgs.builder()
                .group(devs.name())
                .policy(serializeJson(
                    jsonObject(
                        jsonProperty("Version", "2012-10-17"),
                        jsonProperty("Statement", jsonArray(jsonObject(
                            jsonProperty("Action", jsonArray("ec2:Describe*")),
                            jsonProperty("Effect", "Allow"),
                            jsonProperty("Resource", "*")
                        )))
                    )))
                .build());

            new GroupMembership("dev-team", GroupMembershipArgs.builder()
                .group(devs.id())
                .users(userIds)
                .build());
        });
    }
}

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

t0yv0 commented 3 months ago

Yeah this landed in java bypassing pulumi-aws but I think it goes through the conversion pipeline, LMK if it's helpful to pull out the PCL/HCL phases here for this example. Thank you!