// Copyright 2016-2019, Pulumi Corporation
using System;
using System.Collections.Generic;
namespace Pulumi
{
///
/// A bag of optional settings that control a 's behavior.
///
public sealed class ComponentResourceOptions : ResourceOptions
{
private List? _providers;
///
/// An optional set of providers to use for child resources.
///
/// Note: do not provide both and .
///
public List Providers
{
get => _providers ?? (_providers = new List());
set => _providers = value;
}
internal override ResourceOptions Clone()
=> CreateComponentResourceOptionsCopy(this);
///
/// Takes two values and produces a new
/// with the respective
/// properties of merged over the same properties in . The original options objects will be unchanged.
///
/// A new instance will always be returned.
///
/// Conceptually property merging follows these basic rules:
///
/// -
/// If the property is a collection, the final value will be a collection containing the
/// values from each options object.
///
/// -
/// Simple scalar values from (i.e. s,
/// s, s) will replace the values of .
///
/// -
/// values in will be ignored.
///
///
///
public static ComponentResourceOptions Merge(ComponentResourceOptions? options1, ComponentResourceOptions? options2)
{
options1 = options1 != null ? CreateComponentResourceOptionsCopy(options1) : new ComponentResourceOptions();
options2 = options2 != null ? CreateComponentResourceOptionsCopy(options2) : new ComponentResourceOptions();
ExpandProviders(options1);
ExpandProviders(options2);
// first, merge all the normal option values over
MergeNormalOptions(options1, options2);
options1.Providers.AddRange(options2.Providers);
if (options1.Providers.Count == 1)
{
options1.Provider = options1.Providers[0];
options1.Providers.Clear();
}
return options1;
static void ExpandProviders(ComponentResourceOptions options)
{
if (options.Provider != null)
{
options.Providers = new List { options.Provider };
options.Provider = null;
}
}
}
}
}