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

CustomResourceOptions CE #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

CustomResourceOptions CE #29

wants to merge 2 commits into from

Conversation

mvsmal
Copy link
Contributor

@mvsmal mvsmal commented Nov 10, 2023

This PR adds:

  • CustomResourceOptions CE in Pulumi.FSharp.Core
    This is just a hard-coded CE for the Pulumi type (also includes CE for CustomTimeouts)
  • Yield operation in the resources CEs

I've managed to avoid breaking changes and kept the existing dependsOn operation, which will overwrite that property on the passed customResourceOptions. I also added a deprecation notice in the comments.

Here is an example of a generated code:

namespace Pulumi.FSharp

open Pulumi.FSharp
open Pulumi

module Docker =
    open Pulumi.Docker

    let _combine ((rName, rArgs), (lName, lArgs)) =
        (match lName, rName with
         | null, null -> null
         | null, name -> name
         | name, null -> name
         | _ -> failwith "Duplicate name"),
        (List.concat [ lArgs; rArgs ])

    let _combineCros ((rName, rArgs, rCros, rCroI), (lName, lArgs, lCros, lCroI)) =
        (match lName, rName with
         | null, null -> null
         | null, name -> name
         | name, null -> name
         | _ -> failwith "DuplicateName"),
        (List.concat [ lArgs; rArgs ]),
        (List.concat [ lCros; rCros ]),
        (match lCroI, rCroI with
         | null, null -> null
         | null, croi -> croi
         | croi, null -> croi
         | _ -> failwith "DuplicateCroI")

    type ImageBuilder() =


            member _.Yield(_: unit) = null, [ id ], [ id ], null

            member _.Run(name, args, cros, croI) =
                Image(
                    name,
                    List.fold (fun args f -> f args) (ImageArgs()) args,
                    List.fold
                        (fun cros f -> f cros)
                        (match croI with
                         | null -> CustomResourceOptions()
                         | croI -> croI)
                        cros
                )

            member this.Combine(args) = _combineCros args
            member this.For(args, delayedArgs) = this.Combine(args, delayedArgs ())
            member _.Delay(f) = f ()
            member _.Zero _ = ()

            ///Pulumi logical resource name
            [<CustomOperation("name")>]
            member _.Name((_, args, cros, croI), newName) = newName, args, cros, croI

            member _.Yield(arg) =
                null,
                [ (let func (args: ImageArgs) =
                      args.Build <- input arg
                      args

                   ()
                   func) ],
                [ id ],
                null

            ///The image name, of the format repository[:tag], e.g. `docker.io/username/demo-image:v1`.
            ///This reference is not unique to each build and push.For the unique manifest SHA of a pushed docker image, or the local image ID, please use `repoDigest`.
            [<CustomOperation("imageName")>]
            member _.ImageName((name, args, cros, croI), imageName) =
                name,
                List.Cons(
                    (fun (args: ImageArgs) ->
                        args.ImageName <- input imageName
                        args),
                    args
                ),
                cros,
                croI

            ///The image name, of the format repository[:tag], e.g. `docker.io/username/demo-image:v1`.
            ///This reference is not unique to each build and push.For the unique manifest SHA of a pushed docker image, or the local image ID, please use `repoDigest`.
            member _.ImageName((name, args, cros, croI), imageName) =
                name,
                List.Cons(
                    (fun (args: ImageArgs) ->
                        args.ImageName <- io imageName
                        args),
                    args
                ),
                cros,
                croI

            member _.Yield(arg) =
                null,
                [ (let func (args: ImageArgs) =
                      args.Registry <- input arg
                      args

                   ()
                   func) ],
                [ id ],
                null

            ///A flag to skip a registry push.
            [<CustomOperation("skipPush")>]
            member _.SkipPush((name, args, cros, croI), skipPush) =
                name,
                List.Cons(
                    (fun (args: ImageArgs) ->
                        args.SkipPush <- input skipPush
                        args),
                    args
                ),
                cros,
                croI

            ///A flag to skip a registry push.
            member _.SkipPush((name, args, cros, croI), skipPush) =
                name,
                List.Cons(
                    (fun (args: ImageArgs) ->
                        args.SkipPush <- io skipPush
                        args),
                    args
                ),
                cros,
                croI

            ///Obsolete. Use customResourceOptions nested CE. Ensure this resource gets created after its dependency
            [<CustomOperation("dependsOn")>]
            member _.DependsOn((name, args, cros, croI), dependency) =
                name,
                args,
                List.Cons(
                    (fun (cros: CustomResourceOptions) ->
                        cros.DependsOn <- inputList [ input dependency ]
                        cros),
                    cros
                ),
                croI

            ///Obsolete. Use customResourceOptions nested CE. Ensure this resource gets created after its dependency
            member _.DependsOn((name, args, cros, croI), dependency) =
                name,
                args,
                List.Cons(
                    (fun (cros: CustomResourceOptions) ->
                        cros.DependsOn <- inputList (Seq.map input dependency)
                        cros),
                    cros
                ),
                croI

            member _.Yield(croI: CustomResourceOptions) = null, [ id ], [ id ], croI

    ///`Image` builds a Docker image and pushes it Docker and OCI compatible registries.
    ///
    ///*** Operations ***
    ///
    /// - imageName
    ///
    /// - skipPush
    ///
    ///
    ///
    ///*** Nested computational expressions ***
    ///
    /// - dockerBuild
    ///
    /// - registry
    let image = ImageBuilder()

@mvsmal
Copy link
Contributor Author

mvsmal commented Jan 15, 2024

Friendly reminder 🙂

@mvsmal
Copy link
Contributor Author

mvsmal commented Feb 16, 2024

hi @UnoSD
Hope you are fine. Would you have time for reviewing this thing?

@UnoSD
Copy link
Owner

UnoSD commented Feb 17, 2024

Hi @mvsmal, apologies, I forgot this one was open. I will be insanely busy for the rest of Feb, but I'll put this on top of my list for the beginning of March.

@UnoSD
Copy link
Owner

UnoSD commented Mar 21, 2024

hi @mvsmal, thank you for the patience and apologies again. Thing are getting quieter now, so I will try and have a look; by any chance, do you have example code that I can add to the test project to test all the operations in the change? thanks

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.

2 participants