There are two ways:
- run from command line (Gradle)
- example:
./gradlew run --args="--schema-path $HOME/Workspaces/pulumi/schemas/gcp-classic_6.4.0.json --output-directory-path $HOME/Workspaces/generated/pulumi-kotlin-generated/app/src/main/kotlin"
- example:
- run from IntelliJ with
Program arguments
properly set
In order to easily browse generated files one can generate them directly into basic gradle project,
hence --output-directory-path $HOME/Workspaces/generated/pulumi-kotlin-generated/app/src/main/kotlin
--schema-path
– absolute path to provider's schema (see section below for how to download it)--output-directory-path
– absolute path to a directory where the generated code should be stored
Schema is stored in provider's repository, under provider/cmd/pulumi-resource-{{provider-name}}
path.
For example, to download pulumi-aws-native
's schema, open this link
and save the file (Right click 'Download' -> 'Save link as...').
/
encoded
as %2F
(in $ref
).
Use the pulumi package get-schema
command, for example:
pulumi package get-schema 'azure-native' > azure-native-schema.json
Code generation and compilation of large schemas can take time,
in order to test only particular resources one can prepare schema subset with ComputeSchemaSubsetScript.kt
and generate Kotlin SDK out of it.
This script will generate subset with all types referenced by sought-after object.
ComputeSchemaSubsetScript.kt
can be run in two ways:
- from command line:
./gradlew computeSchemaSubset --args="--schema-path $HOME/Workspaces/pulumi/schemas/gcp-classic_6.4.0.json --name gcp:compute/instance:Instance --context resource --output-path $HOME/Workspaces/pulumi/schemas/gcp-classic_6.4.0_instance.json"
- arguments
--full-schema-path
- absolute path to full provider's schema--existing-schema-subset-path
- (optional) absolute path to existing schema subset, objects present there will be contained in result subset--output-path
- (optional) script will save subset schema's contents in this path, if it's not given, schema will be printed tostdout
--name-and-context
- name and kind of object to find in the schema, i.e.gcp:compute/instance:Instance resource
,
possiblecontext
values:function
type
resource
provider
this parameter can be passed multiple times
--shorten-descriptions
- (optional) whentrue
reducesdescription
property length to 100 characters, defaultfalse
--load-provider-with-children
- (optional) whentrue
, considers also provider resource in resulting schema along with types it depends on, defaulttrue
--load-full-parents
- (optional) whentrue
considers objects referencing to object given as value of--name-and-context
, defaultfalse
- arguments
- from IntelliJ with
Program arguments
properly set (possible properties and values like above)
- The provided schema is deserialized (
step1schemaparse
). - The deserialized schema is converted into intermediate representation – graph of type
dependencies (
step2intermediate
). - The intermediate representation is used to generate Kotlin code (
step3codegen
).- Code is generated with KotlinPoet.
- The generated SDK allows to write an idiomatic Kotlin code (see type-safe builders).
- The generated SDK delegates all the work to Pulumi Java SDK.