Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new transforms docs #11851

Merged
merged 2 commits into from
Jul 15, 2024
Merged

Add new transforms docs #11851

merged 2 commits into from
Jul 15, 2024

Conversation

justinvp
Copy link
Member

Adds docs for the new transforms APIs. Ported from pulumi/pulumi-hugo#4044.

@pulumi-bot
Copy link
Collaborator

Comment on lines 307 to 308
length := rta.Props["length"].(pulumi.Float64Output)
rta.Props["length"] = length.ApplyT(func(v float64) float64 { return v * 2 })
Copy link
Contributor

@EronWright EronWright Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great to expand on how to transform the props, like explain that the values are encapsulated as Outputs, that you should expect variations related to secretness (should you?), and that you transform the outputs as explained elsewhere.

Here's an example of how to add a Kubernetes annotation. Would be awesome to show an example like this for each SDK.

const applyPatchForceAnnotation = async (args: pulumi.ResourceTransformArgs) => {
    switch(args.type) {
        case "kubernetes:helm.sh/v4:Chart":
            break;
        default:
            args.props.metadata.annotations = {
                "pulumi.com/patchForce": "true",
                ...args.props.metadata.annotations
            }
    }
    return {
        props: args.props,
        opts: args.opts,
    };
};

// Use Helm to install the Nginx ingress controller
const ingressController = new kubernetes.helm.v4.Chart("ingresscontroller", {
    chart: "nginx-ingress",
    namespace: ingressNs.metadata.name,
    repositoryOpts: {
        repo: "https://helm.nginx.com/stable",
    },
    skipCrds: false,
    values: {
        controller: {
            enableCustomResources: true,
            appprotect: {
                enable: false,
            },
            appprotectdos: {
                enable: false,
            },
            service: {
                extraLabels: appLabels,
            },
        },
    },
    version: "0.14.1",
}, {transforms: [applyPatchForceAnnotation]});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar example in Python:

def apply_patchforce_annotation(args: ResourceTransformArgs):
    if not args.type_ == "kubernetes:helm.sh/v4:Chart":
        if not 'metadata' in args.props:
            args.props['metadata'] = {}
        if not 'annotations' in args.props['metadata']:
            args.props['metadata']['annotations'] = {}
        args.props['metadata']['annotations']['pulumi.com/patchForce'] = 'true'

    return ResourceTransformResult(
        props=args.props,
        opts=args.opts)

ingresscontroller = kubernetes.helm.v4.Chart(
    "ingresscontroller",
    chart="nginx-ingress",
    namespace=ingress_ns.metadata.name,
    repository_opts=kubernetes.helm.v3.RepositoryOptsArgs(
        repo="https://helm.nginx.com/stable",
    ),
    version="0.14.1",
    opts=pulumi.ResourceOptions(transforms=[apply_patchforce_annotation])
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great to expand on how to transform the props, like explain that the values are encapsulated as Outputs, that you should expect variations related to secretness (should you?), and that you transform the outputs as explained elsewhere.

Agree! It's somewhat shown in some of the examples, but I'd like to expand on this as a fast follow.

Would be awesome to show an example like this for each SDK.

Yes. Haven't had a chance to port to each language, but would love to have more examples to show.

Copy link
Contributor

@tgummerer tgummerer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things I noticed while experimenting with transforms based of these docs.

content/docs/concepts/options/transforms.md Outdated Show resolved Hide resolved
content/docs/concepts/options/transforms.md Outdated Show resolved Hide resolved
content/docs/concepts/options/transforms.md Outdated Show resolved Hide resolved
@pulumi-bot
Copy link
Collaborator

@justinvp justinvp marked this pull request as ready for review July 15, 2024 16:20
@justinvp justinvp requested a review from Frassle July 15, 2024 16:20
@justinvp justinvp merged commit a22d806 into master Jul 15, 2024
11 checks passed
@justinvp justinvp deleted the fraser/transforms branch July 15, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants