Kubernetes

Pulumi Official
Package maintained by Pulumi
v3.19.1 published on Wednesday, May 4, 2022 by Pulumi

ConfigGroup

ConfigGroup creates a set of Kubernetes resources from Kubernetes YAML text. The YAML text may be supplied using any of the following methods:

  1. Using a filename or a list of filenames:
  2. Using a file pattern or a list of file patterns:
  3. Using a literal string containing YAML, or a list of such strings:
  4. Any combination of files, patterns, or YAML strings:

Example Usage

Local File

using System.Threading.Tasks;
using Pulumi;
using Pulumi.Kubernetes.Yaml;

class YamlStack : Stack
{
    public YamlStack()
    {
        var helloWorld = new ConfigGroup("example", new ConfigGroupArgs
        {
            Files = new[] { "foo.yaml" }
        });
    }
}
package main

import (
	"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := yaml.NewConfigGroup(ctx, "example",
			&yaml.ConfigGroupArgs{
				Files: []string{"foo.yaml"},
			},
		)
		if err != nil {
			return err
		}

		return nil
	})
}

Coming soon!

from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    files=["foo.yaml"],
)
import * as k8s from "@pulumi/kubernetes";

const example = new k8s.yaml.ConfigGroup("example", {
    files: "foo.yaml",
});

Coming soon!

Multiple Local Files

using System.Threading.Tasks;
using Pulumi;
using Pulumi.Kubernetes.Yaml;

class YamlStack : Stack
{
    public YamlStack()
    {
        var helloWorld = new ConfigGroup("example", new ConfigGroupArgs
        {
            Files = new[] { "foo.yaml", "bar.yaml" }
        });
    }
}
package main

import (
	"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := yaml.NewConfigGroup(ctx, "example",
			&yaml.ConfigGroupArgs{
				Files: []string{"foo.yaml", "bar.yaml"},
			},
		)
		if err != nil {
			return err
		}

		return nil
	})
}

Coming soon!

from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    files=["foo.yaml", "bar.yaml"],
)
import * as k8s from "@pulumi/kubernetes";

const example = new k8s.yaml.ConfigGroup("example", {
    files: ["foo.yaml", "bar.yaml"],
});

Coming soon!

Local File Pattern

using System.Threading.Tasks;
using Pulumi;
using Pulumi.Kubernetes.Yaml;

class YamlStack : Stack
{
    public YamlStack()
    {
        var helloWorld = new ConfigGroup("example", new ConfigGroupArgs
        {
            Files = new[] { "yaml/*.yaml" }
        });
    }
}
package main

import (
	"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := yaml.NewConfigGroup(ctx, "example",
			&yaml.ConfigGroupArgs{
				Files: []string{"yaml/*.yaml"},
			},
		)
		if err != nil {
			return err
		}

		return nil
	})
}

Coming soon!

from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    files=["yaml/*.yaml"],
)
import * as k8s from "@pulumi/kubernetes";

const example = new k8s.yaml.ConfigGroup("example", {
    files: "yaml/*.yaml",
});

Coming soon!

Multiple Local File Patterns

using System.Threading.Tasks;
using Pulumi;
using Pulumi.Kubernetes.Yaml;

class YamlStack : Stack
{
    public YamlStack()
    {
        var helloWorld = new ConfigGroup("example", new ConfigGroupArgs
        {
            Files = new[] { "foo/*.yaml", "bar/*.yaml" }
        });
    }
}
package main

import (
	"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := yaml.NewConfigGroup(ctx, "example",
			&yaml.ConfigGroupArgs{
				Files: []string{"yaml/*.yaml", "bar/*.yaml"},
			},
		)
		if err != nil {
			return err
		}

		return nil
	})
}

Coming soon!

from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    files=["foo/*.yaml", "bar/*.yaml"],
)
import * as k8s from "@pulumi/kubernetes";

const example = new k8s.yaml.ConfigGroup("example", {
    files: ["foo/*.yaml", "bar/*.yaml"],
});

Coming soon!

Literal YAML String

using System.Threading.Tasks;
using Pulumi;
using Pulumi.Kubernetes.Yaml;

class YamlStack : Stack
{
    public YamlStack()
    {
        var helloWorld = new ConfigGroup("example", new ConfigGroupArgs
        {
            Yaml = @"
            apiVersion: v1
            kind: Namespace
            metadata:
              name: foo
            ",
        });
    }
}
package main

import (
	"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := yaml.NewConfigGroup(ctx, "example",
			&yaml.ConfigGroupArgs{
				YAML: []string{
					`
apiVersion: v1
kind: Namespace
metadata:
  name: foo
`,
				},
			})
		if err != nil {
			return err
		}

		return nil
	})
}

Coming soon!

from pulumi_kubernetes.yaml import ConfigGroup

example = ConfigGroup(
    "example",
    yaml=['''
apiVersion: v1
kind: Namespace
metadata:
  name: foo
''']
)
import * as k8s from "@pulumi/kubernetes";

const example = new k8s.yaml.ConfigGroup("example", {
    yaml: `
apiVersion: v1
kind: Namespace
metadata:
  name: foo
`,
})

Coming soon!

YAML with Transformations

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Pulumi;
using Pulumi.Kubernetes.Yaml;

class YamlStack : Stack
{
    public YamlStack()
    {
        var helloWorld = new ConfigGroup("example", new ConfigGroupArgs
        {
            Files = new[] { "foo.yaml" },
            Transformations =
               {
                   LoadBalancerToClusterIP,
                   ResourceAlias,
                   OmitTestPod,
               }
        });

        // Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
        ImmutableDictionary<string, object> LoadBalancerToClusterIP(ImmutableDictionary<string, object> obj, CustomResourceOptions opts)
        {
            if ((string)obj["kind"] == "Service" && (string)obj["apiVersion"] == "v1")
            {
                var spec = (ImmutableDictionary<string, object>)obj["spec"];
                if (spec != null && (string)spec["type"] == "LoadBalancer")
                {
                    return obj.SetItem("spec", spec.SetItem("type", "ClusterIP"));
                }
            }

            return obj;
        }

        // Set a resource alias for a previous name.
        ImmutableDictionary<string, object> ResourceAlias(ImmutableDictionary<string, object> obj, CustomResourceOptions opts)
        {
            if ((string)obj["kind"] == "Deployment")
            {
                opts.Aliases.Add(new Alias { Name = "oldName" });
            }

            return obj;
        }

        // Omit a resource from the Chart by transforming the specified resource definition to an empty List.
        ImmutableDictionary<string, object> OmitTestPod(ImmutableDictionary<string, object> obj, CustomResourceOptions opts)
        {
            var metadata = (ImmutableDictionary<string, object>)obj["metadata"];
            if ((string)obj["kind"] == "Pod" && (string)metadata["name"] == "test")
            {
                return new Dictionary<string, object>
                {
                    ["apiVersion"] = "v1",
                    ["kind"] = "List",
                    ["items"] = new Dictionary<string, object>(),
                }.ToImmutableDictionary();
            }

            return obj;
        }
    }
}
package main

import (
	"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := yaml.NewConfigGroup(ctx, "example",
			&yaml.ConfigGroupArgs{
				Files: []string{"foo.yaml"},
				Transformations: []yaml.Transformation{
					// Make every service private to the cluster, i.e., turn all services into ClusterIP
					// instead of LoadBalancer.
					func(state map[string]interface{}, opts ...pulumi.ResourceOption) {
						if state["kind"] == "Service" {
							spec := state["spec"].(map[string]interface{})
							spec["type"] = "ClusterIP"
						}
					},

					// Set a resource alias for a previous name.
					func(state map[string]interface{}, opts ...pulumi.ResourceOption) {
						if state["kind"] == "Deployment" {
							aliases := pulumi.Aliases([]pulumi.Alias{
								{
									Name: pulumi.String("oldName"),
								},
							})
							opts = append(opts, aliases)
						}
					},

					// Omit a resource from the Chart by transforming the specified resource definition
					// to an empty List.
					func(state map[string]interface{}, opts ...pulumi.ResourceOption) {
						name := state["metadata"].(map[string]interface{})["name"]
						if state["kind"] == "Pod" && name == "test" {
							state["apiVersion"] = "core/v1"
							state["kind"] = "List"
						}
					},
				},
			},
		)
		if err != nil {
			return err
		}

		return nil
	})
}

Coming soon!

from pulumi_kubernetes.yaml import ConfigFile

# Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
def make_service_private(obj, opts):
    if obj["kind"] == "Service" and obj["apiVersion"] == "v1":
        try:
            t = obj["spec"]["type"]
            if t == "LoadBalancer":
                obj["spec"]["type"] = "ClusterIP"
        except KeyError:
            pass


# Set a resource alias for a previous name.
def alias(obj, opts):
    if obj["kind"] == "Deployment":
        opts.aliases = ["oldName"]


# Omit a resource from the Chart by transforming the specified resource definition to an empty List.
def omit_resource(obj, opts):
    if obj["kind"] == "Pod" and obj["metadata"]["name"] == "test":
        obj["apiVersion"] = "v1"
        obj["kind"] = "List"


example = ConfigGroup(
    "example",
    files=["foo.yaml"],
    transformations=[make_service_private, alias, omit_resource],
)
import * as k8s from "@pulumi/kubernetes";

const example = new k8s.yaml.ConfigGroup("example", {
    files: "foo.yaml",
    transformations: [
        // Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
        (obj: any, opts: pulumi.CustomResourceOptions) => {
            if (obj.kind === "Service" && obj.apiVersion === "v1") {
                if (obj.spec && obj.spec.type && obj.spec.type === "LoadBalancer") {
                    obj.spec.type = "ClusterIP";
                }
            }
        },

        // Set a resource alias for a previous name.
        (obj: any, opts: pulumi.CustomResourceOptions) => {
            if (obj.kind === "Deployment") {
                opts.aliases = [{ name: "oldName" }]
            }
        },

        // Omit a resource from the Chart by transforming the specified resource definition to an empty List.
        (obj: any, opts: pulumi.CustomResourceOptions) => {
            if (obj.kind === "Pod" && obj.metadata.name === "test") {
                obj.apiVersion = "v1"
                obj.kind = "List"
            }
        },
    ],
});

Coming soon!

Create a ConfigGroup Resource

new ConfigGroup(name: string, args?: ConfigGroupOpts, opts?: ComponentResourceOptions);
@overload
def ConfigGroup(file,
                opts=None,
                transformations=None,
                resource_prefix=None)
@overload
def ConfigGroup(file,
                opts=None,
                transformations=None,
                resource_prefix=None)
func NewConfigGroup(ctx *Context, name string, args *ConfigGroupArgs, opts ...ResourceOption) (*ConfigGroup, error)
public ConfigGroup(string name, ConfigGroupArgs? args = null, ComponentResourceOptions? opts = null)
public ConfigGroup(String name, ConfigGroupArgs args)
public ConfigGroup(String name, ConfigGroupArgs args, ComponentResourceOptions options)
type: kubernetes:yaml:ConfigGroup
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args ConfigGroupOpts
The arguments to resource properties.
opts ComponentResourceOptions
Bag of options to control resource's behavior.
file
opts
transformations
resource_prefix
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args ConfigGroupArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args ConfigGroupArgs
The arguments to resource properties.
opts ComponentResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args ConfigGroupArgs
The arguments to resource properties.
options ComponentResourceOptions
Bag of options to control resource's behavior.

ConfigGroup Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The ConfigGroup resource accepts the following input properties:

Files string | List<string>

Set of paths or a URLs that uniquely identify files.

Objs object | List<object>

Objects representing Kubernetes resources.

ResourcePrefix string

An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".

Transformations List<object>

A set of transformations to apply to Kubernetes resource definitions before registering with engine.

Yaml string | List<string>

YAML text containing Kubernetes resource definitions.

Files string | []string

Set of paths or a URLs that uniquely identify files.

Objs interface{} | []interface{}

Objects representing Kubernetes resources.

ResourcePrefix string

An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".

Transformations []interface{}

A set of transformations to apply to Kubernetes resource definitions before registering with engine.

Yaml string | []string

YAML text containing Kubernetes resource definitions.

files String | List

Set of paths or a URLs that uniquely identify files.

objs Object | List

Objects representing Kubernetes resources.

resourcePrefix String

An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".

transformations List

A set of transformations to apply to Kubernetes resource definitions before registering with engine.

yaml String | List

YAML text containing Kubernetes resource definitions.

files string | string[]

Set of paths or a URLs that uniquely identify files.

objs any | any[]

Objects representing Kubernetes resources.

resourcePrefix string

An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".

transformations any[]

A set of transformations to apply to Kubernetes resource definitions before registering with engine.

yaml string | string[]

YAML text containing Kubernetes resource definitions.

files str | Sequence[str]

Set of paths or a URLs that uniquely identify files.

objs Any | Sequence[Any]

Objects representing Kubernetes resources.

resource_prefix str

An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".

transformations Sequence[Any]

A set of transformations to apply to Kubernetes resource definitions before registering with engine.

yaml str | Sequence[str]

YAML text containing Kubernetes resource definitions.

files String | List

Set of paths or a URLs that uniquely identify files.

objs Any | List

Objects representing Kubernetes resources.

resourcePrefix String

An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".

transformations List

A set of transformations to apply to Kubernetes resource definitions before registering with engine.

yaml String | List

YAML text containing Kubernetes resource definitions.

Outputs

All input properties are implicitly available as output properties. Additionally, the ConfigGroup resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Resources string

Resources created by the ConfigGroup.

Id string

The provider-assigned unique ID for this managed resource.

Resources string

Resources created by the ConfigGroup.

id String

The provider-assigned unique ID for this managed resource.

resources String

Resources created by the ConfigGroup.

id string

The provider-assigned unique ID for this managed resource.

resources string

Resources created by the ConfigGroup.

id str

The provider-assigned unique ID for this managed resource.

resources str

Resources created by the ConfigGroup.

id String

The provider-assigned unique ID for this managed resource.

resources String

Resources created by the ConfigGroup.

Package Details

Repository
https://github.com/pulumi/pulumi-kubernetes
License
Apache-2.0