Exemple #1
0
 public ComponentSixParent(string name, ComponentResourceOptions options = null)
     : base("my:module:ComponentSixParent-v0", name, options)
 {
     this.child = new ComponentSix("child", new ComponentResourceOptions {
         Parent = this
     });
 }
Exemple #2
0
        public void MergeComponent()
        {
            var awsDefault   = new DependencyProviderResource("urn:pulumi:stack::project::pulumi:providers:aws::default_4_13_0");
            var awsExplicit  = new DependencyProviderResource("urn:pulumi:stack::project::pulumi:providers:aws::explicit");
            var azureDefault = new DependencyProviderResource("urn:pulumi:stack::project::pulumi:providers:azure::default_4_13_0");

            var o1 = new ComponentResourceOptions {
                Providers = new List <ProviderResource> {
                    awsDefault, azureDefault
                },
                Protect = true,
            };

            var o2 = new ComponentResourceOptions {
                Providers = new List <ProviderResource> {
                    awsExplicit
                },
                Protect = false,
            };

            var result = ComponentResourceOptions.Merge(o1, o2);

            Assert.False(result.Protect);
            Assert.Equal(azureDefault, result.Providers[0]);
            Assert.Equal(awsExplicit, result.Providers[1]);
            Assert.Equal(2, result.Providers.Count);
        }
Exemple #3
0
 public ComponentFour(string name, ComponentResourceOptions options = null)
     : base("my:module:ComponentFour", name, options)
 {
     this.resource = new Resource("otherchild", new ComponentResourceOptions {
         Parent = this
     });
 }
Exemple #4
0
 public ComponentFive(string name, ComponentResourceOptions options = null)
     : base("my:module:ComponentFive", name, options)
 {
     this.resource = new Resource("otherchildrenamed", new ComponentResourceOptions
     {
         Parent  = this,
         Aliases = { { new Alias {
                           Name = "otherchild", Parent = this
                       } } },
     });
 }
Exemple #5
0
 public ComponentSixParent(string name, ComponentResourceOptions options = null)
     : base("my:module:ComponentSixParent-v10", name, ComponentResourceOptions.Merge(options, new ComponentResourceOptions
 {
     // Add an alias that references the old type of this resource
     // and then make the base() call with the new type of this resource and the added alias.
     Aliases = GenerateAliases()
 }))
 {
     this.child = new ComponentSix("child", new ComponentResourceOptions {
         Parent = this
     });
 }
Exemple #6
0
        private static ComponentResourceOptions MakeResourceOptions(ComponentResourceOptions?options, Input <string>?id)
        {
            var defaultOptions = new ComponentResourceOptions
            {
                Version = Utilities.Version,
            };
            var merged = ComponentResourceOptions.Merge(defaultOptions, options);

            // Override the ID if one was specified for consistency with other language SDKs.
            merged.Id = id ?? merged.Id;
            return(merged);
        }
Exemple #7
0
 public ComponentThree(string name, ComponentResourceOptions options = null)
     : base("my:module:ComponentThree", name, options)
 {
     // Note that both un-prefixed and parent-name-prefixed child names are supported. For the later, the implicit
     // alias inherited from the parent alias will include replacing the name prefix to match the parent alias name.
     this.resource1 = new Resource($"{name}-child", new ComponentResourceOptions {
         Parent = this
     });
     this.resource2 = new Resource("otherchild", new ComponentResourceOptions {
         Parent = this
     });
 }
Exemple #8
0
 public Component3(string name, ComponentResourceOptions options = null)
     : base("my:module:Component3", name, options)
 {
     new Component2(name + "-child",
                    new ComponentResourceOptions
     {
         Aliases = { new Alias {
                         Parent = options?.Parent, NoParent = options?.Parent == null
                     } },
         Parent = this
     });
 }
Exemple #9
0
 public ComponentSix(string name, ComponentResourceOptions options = null)
     : base("my:module:ComponentSix-v100", name, ComponentResourceOptions.Merge(options, new ComponentResourceOptions
 {
     // Add an alias that references the old type of this resource
     // and then make the base() call with the new type of this resource and the added alias.
     Aliases = GenerateAliases()
 }))
 {
     // The child resource will also pick up an implicit alias due to the new type of the component it is parented to.
     this.resource = new Resource("otherchild", new ComponentResourceOptions {
         Parent = this
     });
 }
Exemple #10
0
 public ComponentFour(string name, ComponentResourceOptions options = null)
     : base("my:differentmodule:ComponentFourWithADifferentTypeName", name, ComponentResourceOptions.Merge(options, new ComponentResourceOptions
 {
     // Add an alias that references the old type of this resource
     // and then make the base() call with the new type of this resource and the added alias.
     Aliases = { new Alias { Type = "my:module:ComponentFour" } }
 }))
 {
     // The child resource will also pick up an implicit alias due to the new type of the component it is parented to.
     this.resource = new Resource("otherchild", new ComponentResourceOptions {
         Parent = this
     });
 }
Exemple #11
0
 public Component4(string name, ComponentResourceOptions options = null)
     : base("my:module:Component4", name,
            ComponentResourceOptions.Merge(
                new ComponentResourceOptions
 {
     Aliases =
     {
         new Alias { NoParent = true },
         new Alias { NoParent = true }
     },
 },
                options))
 {
 }
Exemple #12
0
        public void MergeComponentEmpty()
        {
            var awsDefault   = new DependencyProviderResource("urn:pulumi:stack::project::pulumi:providers:aws::default_4_13_0");
            var awsExplicit  = new DependencyProviderResource("urn:pulumi:stack::project::pulumi:providers:aws::explicit");
            var azureDefault = new DependencyProviderResource("urn:pulumi:stack::project::pulumi:providers:azure::default_4_13_0");

            var o1 = new ComponentResourceOptions {
                Providers = new List <ProviderResource> {
                    awsDefault, azureDefault
                },
                Provider = awsExplicit,
            };

            Assert.Equal(o1.Providers, ComponentResourceOptions.Merge(o1, null).Providers);
        }
Exemple #13
0
        private static ComponentResourceOptions MakeResourceOptions(ComponentResourceOptions?options)
        {
            var defaultOptions = new ComponentResourceOptions
            {
                Version = Utilities.Version,
                Aliases =
                {
                    new Pulumi.Alias {
                        Type = "kubernetes:helm.sh/v2:Chart"
                    },
                },
            };
            var merged = ComponentResourceOptions.Merge(defaultOptions, options);

            return(merged);
        }
        public StaticWebsiteStack()
        {
            // Use existing an Azure Resource Group
            ResourceGroup resourceGroup = ResourceGroup.Get("stef-rg-static-websites", "/subscriptions/ae9255af-d099-4cdc-90a7-241ccb29df68/resourceGroups/stef-rg-static-websites");

            // Create an Azure Storage Account
            var storageAccount = new Account("coronadashboard", new AccountArgs
            {
                ResourceGroupName      = resourceGroup.Name,
                EnableHttpsTrafficOnly = true,
                AccountReplicationType = StorageAccountReplicationTypes.LRS,
                AccountTier            = StorageAccountTiers.Standard,
                AccountKind            = StorageAccountKinds.StorageV2,
                StaticWebsite          = new AccountStaticWebsiteArgs
                {
                    IndexDocument    = "index.html",
                    Error404Document = "404.html"
                }
            });

            // Upload the files from local to azure storage account
            string wwwFolder        = Path.Combine("docs-temp", "wwwroot");
            string currentDirectory = Directory.GetCurrentDirectory();
            var    rootDirectory    = Directory.GetParent(Directory.GetParent(currentDirectory).FullName);
            string sourceFolder     = Path.Combine(rootDirectory.FullName, wwwFolder);

            var blobCollectionArgs = new BlobCollectionArgs
            {
                // Required
                Source               = sourceFolder,
                Type                 = BlobTypes.Block,
                StorageAccountName   = storageAccount.Name,
                StorageContainerName = "$web",

                // Optional
                AccessTier = BlobAccessTiers.Hot
            };

            var blobCollectionOptions = new ComponentResourceOptions
            {
                Parent = storageAccount
            };
            var blobCollection = new BlobCollection("coronadashboard-static-website", blobCollectionArgs, blobCollectionOptions);

            // Export the Web address string for the storage account
            StaticEndpoint = storageAccount.PrimaryWebEndpoint;
        }
Exemple #15
0
 public Component(string name, ComponentResourceOptions options = null)
     : base("my:module:Component", name, options)
 {
     // The resource creation was moved from top level to inside the component.
     this.resource = new Resource($"{name}-child",
                                  new ComponentResourceOptions
     {
         // With a new parent
         Parent = this,
         // But with an alias provided based on knowing where the resource existing before - in this case at top
         // level.  We use an absolute URN instead of a relative `Alias` because we are referencing a fixed resource
         // that was in some arbitrary other location in the hierarchy prior to being adopted into this component.
         Aliases = { Pulumi.Urn.Create("res2", "my:module:Resource").Apply(urn => new Alias {
                 Urn = urn
             }) },
     });
 }
Exemple #16
0
        public void MergeComponentSingleton()
        {
            var aws = new DependencyProviderResource("urn:pulumi:stack::project::pulumi:providers:aws::default_4_13_0");
            var o1  = new ComponentResourceOptions {
                Providers = new List <ProviderResource> {
                    aws
                },
            };
            var o2 = new ComponentResourceOptions {
                Protect = true,
            };

            var result = ComponentResourceOptions.Merge(o1, o2);

            Assert.True(result.Protect);
            Assert.Null(result.Provider);
            Assert.Equal(aws, result.Providers[0]);
        }
Exemple #17
0
        /// <summary>
        /// Directory is a component representing a collection of resources described by a kustomize directory (kustomization).
        /// </summary>
        /// <param name="name">Name of the kustomization (e.g., nginx-ingress).</param>
        /// <param name="args">Configuration options for the kustomization.</param>
        /// <param name="options">Resource options.</param>
        public Directory(string name, DirectoryArgs args, ComponentResourceOptions?options = null)
            : base("kubernetes:kustomize:Directory", MakeName(args, name), options)
        {
            name = GetName(args, name);
            var objs = Invokes.KustomizeDirectory(new KustomizeDirectoryArgs {
                Directory = args.Directory
            });
            var configGroupArgs = new ConfigGroupArgs
            {
                ResourcePrefix  = args.ResourcePrefix,
                Objs            = objs,
                Transformations = args.Transformations
            };
            var opts = ComponentResourceOptions.Merge(options, new ComponentResourceOptions {
                Parent = this
            });
            var resources = Parser.Parse(configGroupArgs, opts);

            RegisterResources(resources);
        }
Exemple #18
0
 private Output <ImmutableDictionary <string, KubernetesResource> > ParseTemplate(string text,
                                                                                  List <TransformationAction> transformations, string?resourcePrefix, ImmutableHashSet <Resource> dependsOn,
                                                                                  string?defaultNamespace)
 {
     return(Invokes
            .YamlDecode(new YamlDecodeArgs {
         Text = text, DefaultNamespace = defaultNamespace
     })
            .Apply(objs =>
     {
         var args = new ConfigGroupArgs
         {
             ResourcePrefix = resourcePrefix,
             Objs = objs,
             Transformations = transformations
         };
         var opts = new ComponentResourceOptions {
             Parent = this, DependsOn = dependsOn.ToArray()
         };
         return Parser.Parse(args, opts);
     }));
 }
Exemple #19
0
 public Component(string name, ComponentResourceOptions opts = null)
     : base("testcomponent:index:Component", name, ResourceArgs.Empty, opts, remote: true)
 {
 }
Exemple #20
0
 public Resource(string name, ComponentResourceOptions options = null)
     : base("my:module:Resource", name, options)
 {
 }
Exemple #21
0
 public Component3(string name, ComponentResourceOptions options = null)
     : base("my:module:Component3", name, options)
 {
     new Component2(name + "-child", options);
 }
Exemple #22
0
        private Output <ImmutableDictionary <string, KubernetesResource> > ParseTemplate(Union <ChartArgsUnwrap, LocalChartArgsUnwrap> args, string releaseName, ImmutableHashSet <Resource> dependsOn)
        {
            // Build JSON args to Helm provider invoke.
            var serializeOptions = new JsonSerializerOptions
            {
                IgnoreNullValues = true,
            };

            BaseChartArgsUnwrap cfgBase;

            // Convert args to JSON string format expected by the invoke function.
            JsonOpts jsonOpts;
            string   jsonOptsString;

            if (args.IsT0)
            {
                var cfg = args.AsT0;
                cfgBase  = cfg;
                jsonOpts = new JsonOpts
                {
                    ApiVersions = cfgBase.ApiVersions,
                    IncludeTestHookResources = cfgBase.IncludeTestHookResources,
                    Namespace   = cfgBase.Namespace,
                    Values      = cfgBase.Values,
                    ReleaseName = releaseName,
                    Repo        = cfg.Repo,
                    Chart       = cfg.Chart,
                    Version     = cfg.Version,
                };
                if (cfg.FetchOptions != null)
                {
                    jsonOpts.FetchOptions = new JsonOptsFetch
                    {
                        Version     = cfg.FetchOptions.Version,
                        CAFile      = cfg.FetchOptions.CAFile,
                        CertFile    = cfg.FetchOptions.CertFile,
                        KeyFile     = cfg.FetchOptions.KeyFile,
                        Destination = cfg.FetchOptions.Destination,
                        Keyring     = cfg.FetchOptions.Keyring,
                        Password    = cfg.FetchOptions.Password,
                        Repo        = cfg.FetchOptions.Repo,
                        UntarDir    = cfg.FetchOptions.UntarDir,
                        Username    = cfg.FetchOptions.Username,
                        Home        = cfg.FetchOptions.Home,
                        Devel       = cfg.FetchOptions.Devel,
                        Prov        = cfg.FetchOptions.Prov,
                        Untar       = cfg.FetchOptions.Untar,
                        Verify      = cfg.FetchOptions.Verify,
                    };
                }
            }
            else
            {
                var cfg = args.AsT1;
                cfgBase  = cfg;
                jsonOpts = new JsonOpts
                {
                    ApiVersions = cfgBase.ApiVersions,
                    IncludeTestHookResources = cfgBase.IncludeTestHookResources,
                    Namespace   = cfgBase.Namespace,
                    Values      = cfgBase.Values,
                    ReleaseName = releaseName,
                    Path        = cfg.Path,
                };
            }
            jsonOptsString = JsonSerializer.Serialize(jsonOpts, serializeOptions);

            return(Invokes
                   .HelmTemplate(new HelmTemplateArgs {
                JsonOpts = jsonOptsString
            })
                   .Apply(objs =>
            {
                var args = new ConfigGroupArgs
                {
                    ResourcePrefix = cfgBase.ResourcePrefix,
                    Objs = objs,
                    Transformations = cfgBase.Transformations
                };
                var opts = new ComponentResourceOptions {
                    Parent = this, DependsOn = dependsOn.ToArray()
                };
                return Parser.Parse(args, opts);
            }));
        }
        private static void ConfigureKubernetesCluster(AzureResourceBag azureResources, PetDoctorClusterOptions clusterOptions)
        {
            var componentOpts = new ComponentResourceOptions
            {
                DependsOn = azureResources.Cluster,
                Provider  = azureResources.ClusterProvider
            };

            var customOpts = new CustomResourceOptions
            {
                DependsOn = azureResources.Cluster,
                Provider  = azureResources.ClusterProvider
            };

            var aadPodIdentityDeployment = new ConfigFile("k8s-aad-pod-identity", new ConfigFileArgs
            {
                File = "https://raw.githubusercontent.com/Azure/aad-pod-identity/master/deploy/infra/deployment-rbac.yaml"
            }, componentOpts);

            var certManagerDeployment = new ConfigFile("k8s-cert-manager", new ConfigFileArgs
            {
                File = "https://raw.githubusercontent.com/jetstack/cert-manager/release-0.8/deploy/manifests/00-crds.yaml"
            }, componentOpts);

            var nginxDeployment = new ConfigFile("k8s-nginx-ingress", new ConfigFileArgs
            {
                File =
                    "https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.34.1/deploy/static/provider/cloud/deploy.yaml"
            }, componentOpts);

            var clusterNamespace = new Namespace("k8s-namespace", new NamespaceArgs
            {
                Metadata = new ObjectMetaArgs
                {
                    Name = clusterOptions.Namespace
                }
            }, customOpts);

            var clusterIssuer = new CustomResource("k8s-cert-manager-cluster-issuer", new CertManagerClusterIssuerResourceArgs
            {
                Metadata = new ObjectMetaArgs
                {
                    Name = "letsencrypt-prod"
                },
                Spec = new CertManagerClusterIssuerSpecArgs
                {
                    Acme = new CertManagerClusterIssuerAcmeArgs
                    {
                        Email  = clusterOptions.CertificateIssuerAcmeEmail,
                        Server = "https://acme-v02.api.letsencrypt.org/directory",
                        PrivateKeySecretRef = new CertManagerClusterIssuerAcmeSecretArgs
                        {
                            Name = "letsencrypt-prod"
                        }
                    }
                }
            }, customOpts);

            var certs = new CustomResource("k8s-cert-manager-domain-cert", new CertManagerCertificateResourceArgs
            {
                Metadata = new ObjectMetaArgs
                {
                    Name = "tls-secret"
                },
                Spec = new CertManagerCertificateSpecArgs
                {
                    SecretName = "tls-secret",
                    DnsNames   = clusterOptions.Domain,
                    Acme       = new CertManagerCertificateAcmeArgs
                    {
                        Config = new CertManagerCertificateAcmeConfigArgs
                        {
                            Http = new CertManagerCertificateAcmeConfigHttpArgs
                            {
                                IngressClass = "nginx"
                            },
                            Domains = clusterOptions.Domain
                        }
                    },
                    IssuerRef = new CertManagerCertificateIssuerRefArgs
                    {
                        Name = "letsencrypt-prod",
                        Kind = "ClusterIssuer"
                    }
                }
            }, customOpts);
        }