Beispiel #1
0
 /// <summary>
 /// Create a Stack with stack resources defined in derived class constructor.
 /// </summary>
 public Stack(StackOptions?options = null)
     : base(_rootPulumiStackTypeName,
            $"{Deployment.Instance.ProjectName}-{Deployment.Instance.StackName}",
            ConvertOptions(options))
 {
     Deployment.InternalInstance.Stack = this;
 }
Beispiel #2
0
 /// <summary>
 /// Create a Stack with stack resources created by the <c>init</c> callback.
 /// An instance of this will be automatically created when any <see
 /// cref="Deployment.RunAsync(Action)"/> overload is called.
 /// </summary>
 internal Stack(Func <Task <IDictionary <string, object?> > > init, StackOptions?options) : this(options)
 {
     try
     {
         this.Outputs = Output.Create(RunInitAsync(init));
     }
     finally
     {
         this.RegisterOutputs(this.Outputs);
     }
 }
Beispiel #3
0
        private static ComponentResourceOptions?ConvertOptions(StackOptions?options)
        {
            if (options == null)
            {
                return(null);
            }

            return(new ComponentResourceOptions
            {
                ResourceTransformations = options.ResourceTransformations
            });
        }
            public Task <int> RunAsync(Func <Task <IDictionary <string, object?> > > func, StackOptions?options)
            {
                var stack = new Stack(func, options);

                RegisterTask("User program code.", stack.Outputs.DataTask);
                return(WhileRunningAsync());
            }
Beispiel #5
0
 /// <summary>
 /// <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/> is an
 /// entry-point to a Pulumi application. .NET applications should perform all startup logic
 /// they need in their <c>Main</c> method and then end with:
 /// <para>
 /// <c>
 /// static Task&lt;int&gt; Main(string[] args)
 /// {
 ///     // program initialization code ...
 ///
 ///     return Deployment.Run(async () =>
 ///     {
 ///         // Code that creates resources.
 ///     });
 /// }
 /// </c>
 /// </para>
 /// Importantly: Cloud resources cannot be created outside of the lambda passed to any of the
 /// <see cref="Deployment.RunAsync(Action)"/> overloads.  Because cloud Resource construction is
 /// inherently asynchronous, the result of this function is a <see cref="Task{T}"/> which should
 /// then be returned or awaited.  This will ensure that any problems that are encountered during
 /// the running of the program are properly reported.  Failure to do this may lead to the
 /// program ending early before all resources are properly registered.
 /// <para/>
 /// The function passed to <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/>
 /// can optionally return an <see cref="IDictionary{TKey, TValue}"/>.  The keys and values
 /// in this dictionary will become the outputs for the Pulumi Stack that is created.
 /// </summary>
 /// <param name="func">Callback that creates stack resources.</param>
 /// <param name="options">Stack options.</param>
 public static Task <int> RunAsync(Func <Task <IDictionary <string, object?> > > func, StackOptions?options = null)
 => CreateRunner().RunAsync(func, options);
Beispiel #6
0
 /// <summary>
 /// <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/> is an
 /// entry-point to a Pulumi application. .NET applications should perform all startup logic
 /// they need in their <c>Main</c> method and then end with:
 /// <para>
 /// <c>
 /// static Task&lt;int&gt; Main(string[] args)
 /// {
 ///     // program initialization code ...
 ///
 ///     return Deployment.Run(async () =>
 ///     {
 ///         // Code that creates resources.
 ///     });
 /// }
 /// </c>
 /// </para>
 /// Importantly: Cloud resources cannot be created outside of the lambda passed to any of the
 /// <see cref="Deployment.RunAsync(Action)"/> overloads.  Because cloud Resource construction is
 /// inherently asynchronous, the result of this function is a <see cref="Task{T}"/> which should
 /// then be returned or awaited.  This will ensure that any problems that are encountered during
 /// the running of the program are properly reported.  Failure to do this may lead to the
 /// program ending early before all resources are properly registered.
 /// <para/>
 /// The function passed to <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/>
 /// can optionally return an <see cref="IDictionary{TKey, TValue}"/>.  The keys and values
 /// in this dictionary will become the outputs for the Pulumi Stack that is created.
 /// </summary>
 /// <param name="func">Callback that creates stack resources.</param>
 /// <param name="options">Stack options.</param>
 public static Task <int> RunAsync(Func <Task <IDictionary <string, object?> > > func, StackOptions?options = null)
 => CreateRunnerAndRunAsync(() => new Deployment(), runner => runner.RunAsync(func, options));
Beispiel #7
0
        public static StackOptions Setup(bool disableSubscription = false, bool disableResourceGroup = false, bool disableLocation = false, bool disableAutoNaming = false, StackOptions?options = null)
        {
            options ??= new StackOptions();

            if (!disableSubscription)
            {
                options.ResourceTransformations.Add(AmbientSubscription.TransformDelegate);
            }
            if (!disableResourceGroup)
            {
                options.ResourceTransformations.Add(AmbientResourceGroup.TransformDelegate);
            }
            if (!disableLocation)
            {
                options.ResourceTransformations.Add(AmbientLocation.TransformDelegate);
            }
            if (!disableAutoNaming)
            {
                options.ResourceTransformations.Add(AutoNaming.TransformDelegate);
            }

            return(options);
        }
Beispiel #8
0
            Task <int> IRunner.RunAsync(Func <Task <IDictionary <string, object?> > > func, StackOptions?options)
            {
                var stack = new Stack(func, options);

                RegisterTask($"{nameof(RunAsync)}: {stack.GetType().FullName}", stack.Outputs.DataTask);
                return(WhileRunningAsync());
            }