예제 #1
0
        /// <summary>
        /// Takes two ResourceOptions values and produces a new ResourceOptions with the respective
        /// properties of <paramref name="options2"/> merged over the same properties in <paramref
        /// name="options1"/>.  The original options objects will be unchanged.
        /// <para/>
        /// A new instance will always be returned.
        /// <para/>
        /// Conceptually property merging follows these basic rules:
        /// <list type="number">
        /// <item>
        /// If the property is a collection, the final value will be a collection containing the
        /// values from each options object.
        /// </item>
        /// <item>
        /// Simple scaler values from <paramref name="options2"/> (i.e. <see cref="string"/>s,
        /// <see cref="int"/>s, <see cref="bool"/>s) will replace the values of <paramref
        /// name="options1"/>.
        /// </item>
        /// <item>
        /// <see langword="null"/> values in <paramref name="options2"/> will be ignored.
        /// </item>
        /// </list>
        /// </summary>
        public static ResourceOptions Merge(ResourceOptions?options1, ResourceOptions?options2)
        {
            options1 ??= new ResourceOptions();
            options2 ??= new ResourceOptions();

            if ((options1 is CustomResourceOptions && options2 is ComponentResourceOptions) ||
                (options1 is ComponentResourceOptions && options2 is CustomResourceOptions))
            {
                throw new ArgumentException(
                          $"Cannot merge a {nameof(CustomResourceOptions)} and {nameof(ComponentResourceOptions)} together.");
            }

            // make an appropriate copy of both options bag, then the copy of options2 into the copy
            // of options1 and return the copy of options1.
            if (options1 is CustomResourceOptions || options2 is CustomResourceOptions)
            {
                return(MergeCustomOptions(
                           CreateCustomResourceOptionsCopy(options1),
                           CreateCustomResourceOptionsCopy(options2)));
            }
            else if (options1 is ComponentResourceOptions || options2 is ComponentResourceOptions)
            {
                return(MergeComponentOptions(
                           CreateComponentResourceOptionsCopy(options1),
                           CreateComponentResourceOptionsCopy(options2)));
            }
            else
            {
                return(MergeNormalOptions(
                           CreateResourceOptionsCopy(options1),
                           CreateResourceOptionsCopy(options2)));
            }
예제 #2
0
        /// <summary>
        /// Creates and registers a new component resource.  <paramref name="type"/> is the fully
        /// qualified type token and <paramref name="name"/> is the "name" part to use in creating a
        /// stable and globally unique URN for the object. <c>options.parent</c> is the optional parent
        /// for this component, and [options.dependsOn] is an optional list of other resources that
        /// this resource depends on, controlling the order in which we perform resource operations.
        /// </summary>
#pragma warning disable RS0022 // Constructor make noninheritable base class inheritable
        public ComponentResource(string type, string name, ResourceOptions?options = null)
            : base(type, name, custom: false,
                   args: ResourceArgs.Empty,
                   options ?? new ComponentResourceOptions())
#pragma warning restore RS0022 // Constructor make noninheritable base class inheritable
        {
        }
예제 #3
0
        public CosmosApp(string name, CosmosAppArgs args, ResourceOptions?options = null)
            : base("examples:azure:CosmosApp", name, options)
        {
            if (args.Locations == null)
            {
                throw new ArgumentException(nameof(args.Locations));
            }

            var primaryLocation = args.Locations.ToOutput().Apply(ls => ls[0]);
            var locations       = args.Locations.ToOutput();

            var cosmosAccount = new CosmosDB.Account($"cosmos-{name}",
                                                     new CosmosDB.AccountArgs
            {
                ResourceGroupName = args.ResourceGroupName,
                Location          = primaryLocation,
                GeoLocations      = locations.Apply(ls =>
                                                    ls.Select((l, i) =>
                {
                    return(new CosmosDB.AccountGeoLocation
                    {
                        Location = l,
                        FailoverPriority = i
                    });
                })),
                OfferType         = "Standard",
                ConsistencyPolicy = new CosmosDB.AccountConsistencyPolicy
                {
                    ConsistencyLevel = "Session",
                },
            });
        }
예제 #4
0
 /// <summary>
 /// Creates and registers a new provider resource for a particular package.
 /// </summary>
 public ProviderResource(
     string package, string name,
     ResourceArgs args, ResourceOptions?options = null)
     : base($"pulumi:providers:{package}", name, args, options)
 {
     this.Package = package;
 }
    public ArchiveFunctionApp(string name, ArchiveFunctionAppArgs args, ResourceOptions?options = null)
        : base("examples:azure:ArchiveFunctionApp", name, options)
    {
        var opts = CustomResourceOptions.Merge(options, new CustomResourceOptions {
            Parent = this
        });

        var storageAccount = new Account($"sa{args.Location}", new AccountArgs
        {
            ResourceGroupName      = args.ResourceGroupName,
            Location               = args.Location,
            AccountReplicationType = "LRS",
            AccountTier            = "Standard",
        }, opts);

        var appServicePlan = new Plan($"asp-{args.Location}", new PlanArgs
        {
            ResourceGroupName = args.ResourceGroupName,
            Location          = args.Location,
            Kind = "FunctionApp",
            Sku  = new PlanSkuArgs
            {
                Tier = "Dynamic",
                Size = "Y1",
            },
        }, opts);

        var container = new Container($"zips-{args.Location}", new ContainerArgs
        {
            StorageAccountName  = storageAccount.Name,
            ContainerAccessType = "private",
        }, opts);

        var blob = new ZipBlob($"zip-{args.Location}", new ZipBlobArgs
        {
            StorageAccountName   = storageAccount.Name,
            StorageContainerName = container.Name,
            Type    = "block",
            Content = args.Archive,
        }, opts);

        var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount);

        args.AppSettings.Add("runtime", "dotnet");
        args.AppSettings.Add("WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl);

        var app = new FunctionApp($"app-{args.Location}", new FunctionAppArgs
        {
            ResourceGroupName       = args.ResourceGroupName,
            Location                = args.Location,
            AppServicePlanId        = appServicePlan.Id,
            AppSettings             = args.AppSettings,
            StorageConnectionString = storageAccount.PrimaryConnectionString,
            Version = "~2",
        }, opts);

        this.AppId = app.Id;
    }
예제 #6
0
 /// <summary>
 /// Create a <see cref="StackReference"/> resource with the given unique name, arguments, and options.
 /// <para />
 /// If args is not specified, the name of the referenced stack will be the name of the StackReference resource.
 /// </summary>
 /// <param name="name">The unique name of the stack reference.</param>
 /// <param name="args">The arguments to use to populate this resource's properties.</param>
 /// <param name="options">A bag of options that control this resource's behavior.</param>
 public StackReference(string name, StackReferenceArgs?args = null, ResourceOptions?options = null)
     : base("pulumi:pulumi:StackReference",
            name,
            new StackReferenceArgs {
     Name = args?.Name ?? name
 },
            CustomResourceOptions.Merge(options, new CustomResourceOptions { Id = args?.Name ?? name }))
 {
 }
예제 #7
0
        /// <summary>
        /// Creates and registers a new managed resource.  t is the fully qualified type token and
        /// name is the "name" part to use in creating a stable and globally unique URN for the
        /// object. dependsOn is an optional list of other resources that this resource depends on,
        /// controlling the order in which we perform resource operations.Creating an instance does
        /// not necessarily perform a create on the physical entity which it represents, and
        /// instead, this is dependent upon the diffing of the new goal state compared to the
        /// current known resource state.
        /// </summary>
#pragma warning disable RS0022 // Constructor make noninheritable base class inheritable
        public CustomResource(string type, string name, ResourceArgs?args, ResourceOptions?options = null)
            : base(type, name, custom: true, args ?? ResourceArgs.Empty, options ?? new ResourceOptions())
#pragma warning restore RS0022 // Constructor make noninheritable base class inheritable
        {
            if (options is ComponentResourceOptions componentOpts && componentOpts.Providers != null)
            {
                throw new ResourceException("Do not supply 'providers' option to a CustomResource. Did you mean 'provider' instead?", this);
            }
        }
예제 #8
0
        internal static ComponentResourceOptions CreateComponentResourceOptionsCopy(ResourceOptions?options)
        {
            var copy = CreateCopy <ComponentResourceOptions>(options ?? new ComponentResourceOptions());

            var componentOptions = options as ComponentResourceOptions;

            copy.Providers = componentOptions?.Providers.ToList() ?? new List <ProviderResource>();

            return(copy);
        }
예제 #9
0
        private static ResourceOptions MakeResourceOptions(ResourceOptions?options, Input <string>?id)
        {
            var defaultOptions = new ResourceOptions
            {
                Version = Utilities.Version,
            };
            var merged = ResourceOptions.Merge(defaultOptions, options);

            // Override the ID if one was specified for consistency with other language SDKs.
            merged.Id = id ?? merged.Id;
            return(merged);
        }
예제 #10
0
        internal static CustomResourceOptions CreateCustomResourceOptionsCopy(ResourceOptions?options)
        {
            var copy = CreateCopy <CustomResourceOptions>(options ?? new CustomResourceOptions());

            var customOptions = options as CustomResourceOptions;

            copy.AdditionalSecretOutputs = customOptions?.AdditionalSecretOutputs.ToList() ?? new List <string>();
            copy.DeleteBeforeReplace     = customOptions?.DeleteBeforeReplace;
            copy.ImportId = customOptions?.ImportId;

            return(copy);
        }
예제 #11
0
 /// <summary>
 /// Create a Provider resource with the given unique name, arguments, and options.
 /// </summary>
 ///
 /// <param name="name">The unique name of the resource</param>
 /// <param name="args">The arguments used to populate this resource's properties</param>
 /// <param name="options">A bag of options that control this resource's behavior</param>
 public Provider(string name, ProviderArgs?args = null, ResourceOptions?options = null)
     : base("digitalocean", name, args, MakeResourceOptions(options, ""))
 {
 }
예제 #12
0
 /// <summary>
 /// Create a Provider resource with the given unique name, arguments, and options.
 /// </summary>
 ///
 /// <param name="name">The unique name of the resource</param>
 /// <param name="args">The arguments used to populate this resource's properties</param>
 /// <param name="options">A bag of options that control this resource's behavior</param>
 public Provider(string name, ProviderArgs?args = null, ResourceOptions?options = null)
     : base("aws", name, args ?? ResourceArgs.Empty, MakeResourceOptions(options, ""))
 {
 }