Last active
November 4, 2021 14:05
-
-
Save pawelprazak/61dc14021206aeaee2eb323b1996fba0 to your computer and use it in GitHub Desktop.
Pulumi Java prototype API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import io.pulumi.Config; | |
import io.pulumi.Stack; | |
import io.pulumi.core.Output; | |
import io.pulumi.core.internal.annotations.OutputExport; | |
import io.pulumi.deployment.Deployment; | |
import org.example.k8s.core.v1.Namespace; | |
import org.example.k8s.core.v1.Secret; | |
import org.example.k8s.meta.v1.ObjectMeta; | |
import java.nio.charset.StandardCharsets; | |
import java.util.Base64; | |
import java.util.Map; | |
import java.util.stream.Collectors; | |
public class Main { | |
public static class MyStack extends Stack { | |
@OutputExport(type = String.class) | |
public final Output<String> theNamespace; | |
@OutputExport(type = String.class) | |
public final Output<String> theSecret; | |
@OutputExport(type = Map.class, parameters = {String.class, String.class}) | |
public final Output<Map<String, String>> theSecretData; | |
public MyStack() { | |
var config = Config.of("example-jvm"); | |
var name = config.require("name"); | |
var ns = new Namespace(name, Namespace.args() | |
.setMetadata( | |
ObjectMeta.args() | |
.setName(name) | |
.setLabels(Map.of("app", name)) | |
.build() | |
).build() | |
); | |
this.theNamespace = Output.allOutputs( | |
ns.getApiVersion(), | |
ns.getKind(), | |
ns.getMetadata().applyOptional(ObjectMeta.Result::getName) | |
).applyValue(ss -> String.join("/", ss)); | |
var secret = new Secret("my-secret", Secret.args() | |
.setMetadata( | |
ObjectMeta.args() | |
.setNamespace( | |
ns.getMetadata() | |
.applyOptional(ObjectMeta.Result::getName) | |
.toInput()) | |
.build()) | |
.setData(Map.of("key", Base64.getEncoder().encodeToString("value".getBytes(StandardCharsets.UTF_8)))) | |
.build() | |
); | |
this.theSecret = secret.getMetadata().applyOptional(ObjectMeta.Result::getName); | |
this.theSecretData = secret.getData().applyValue( | |
d -> d.entrySet().stream().peek(System.out::println).collect(Collectors.toMap( | |
Map.Entry::getKey, | |
Map.Entry::getValue | |
))); | |
} | |
} | |
public static void main(String[] args) { | |
var code = Deployment.runAsyncStack(MyStack.class).join(); | |
System.out.println("Example ended with: " + code); | |
System.exit(code); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config: | |
example-jvm:name: hello |
Author
pawelprazak
commented
Oct 28, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment