All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pulumi.gcp.compute.kotlin.MachineImage.kt Maven / Gradle / Ivy

Go to download

Build cloud applications and infrastructure by combining the safety and reliability of infrastructure as code with the power of the Kotlin programming language.

There is a newer version: 8.12.0.0
Show newest version
@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.gcp.compute.kotlin

import com.pulumi.core.Output
import com.pulumi.gcp.compute.kotlin.outputs.MachineImageMachineImageEncryptionKey
import com.pulumi.gcp.compute.kotlin.outputs.MachineImageMachineImageEncryptionKey.Companion.toKotlin
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List

/**
 * Builder for [MachineImage].
 */
@PulumiTagMarker
public class MachineImageResourceBuilder internal constructor() {
    public var name: String? = null

    public var args: MachineImageArgs = MachineImageArgs()

    public var opts: CustomResourceOptions = CustomResourceOptions()

    /**
     * @param name The _unique_ name of the resulting resource.
     */
    public fun name(`value`: String) {
        this.name = value
    }

    /**
     * @param block The arguments to use to populate this resource's properties.
     */
    public suspend fun args(block: suspend MachineImageArgsBuilder.() -> Unit) {
        val builder = MachineImageArgsBuilder()
        block(builder)
        this.args = builder.build()
    }

    /**
     * @param block A bag of options that control this resource's behavior.
     */
    public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
        this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
    }

    internal fun build(): MachineImage {
        val builtJavaResource = com.pulumi.gcp.compute.MachineImage(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return MachineImage(builtJavaResource)
    }
}

/**
 * Represents a Machine Image resource. Machine images store all the configuration,
 * metadata, permissions, and data from one or more disks required to create a
 * Virtual machine (VM) instance.
 * To get more information about MachineImage, see:
 * * [API documentation](https://cloud.google.com/compute/docs/reference/rest/beta/machineImages)
 * * How-to Guides
 *     * [Official Documentation](https://cloud.google.com/compute/docs/machine-images)
 * ## Example Usage
 * ### Machine Image Basic
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const vm = new gcp.compute.Instance("vm", {
 *     name: "my-vm",
 *     machineType: "e2-medium",
 *     bootDisk: {
 *         initializeParams: {
 *             image: "debian-cloud/debian-11",
 *         },
 *     },
 *     networkInterfaces: [{
 *         network: "default",
 *     }],
 * });
 * const image = new gcp.compute.MachineImage("image", {
 *     name: "my-image",
 *     sourceInstance: vm.selfLink,
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * vm = gcp.compute.Instance("vm",
 *     name="my-vm",
 *     machine_type="e2-medium",
 *     boot_disk=gcp.compute.InstanceBootDiskArgs(
 *         initialize_params=gcp.compute.InstanceBootDiskInitializeParamsArgs(
 *             image="debian-cloud/debian-11",
 *         ),
 *     ),
 *     network_interfaces=[gcp.compute.InstanceNetworkInterfaceArgs(
 *         network="default",
 *     )])
 * image = gcp.compute.MachineImage("image",
 *     name="my-image",
 *     source_instance=vm.self_link)
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var vm = new Gcp.Compute.Instance("vm", new()
 *     {
 *         Name = "my-vm",
 *         MachineType = "e2-medium",
 *         BootDisk = new Gcp.Compute.Inputs.InstanceBootDiskArgs
 *         {
 *             InitializeParams = new Gcp.Compute.Inputs.InstanceBootDiskInitializeParamsArgs
 *             {
 *                 Image = "debian-cloud/debian-11",
 *             },
 *         },
 *         NetworkInterfaces = new[]
 *         {
 *             new Gcp.Compute.Inputs.InstanceNetworkInterfaceArgs
 *             {
 *                 Network = "default",
 *             },
 *         },
 *     });
 *     var image = new Gcp.Compute.MachineImage("image", new()
 *     {
 *         Name = "my-image",
 *         SourceInstance = vm.SelfLink,
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		vm, err := compute.NewInstance(ctx, "vm", &compute.InstanceArgs{
 * 			Name:        pulumi.String("my-vm"),
 * 			MachineType: pulumi.String("e2-medium"),
 * 			BootDisk: &compute.InstanceBootDiskArgs{
 * 				InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
 * 					Image: pulumi.String("debian-cloud/debian-11"),
 * 				},
 * 			},
 * 			NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
 * 				&compute.InstanceNetworkInterfaceArgs{
 * 					Network: pulumi.String("default"),
 * 				},
 * 			},
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewMachineImage(ctx, "image", &compute.MachineImageArgs{
 * 			Name:           pulumi.String("my-image"),
 * 			SourceInstance: vm.SelfLink,
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		return nil
 * 	})
 * }
 * ```
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.gcp.compute.Instance;
 * import com.pulumi.gcp.compute.InstanceArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceBootDiskArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceBootDiskInitializeParamsArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceNetworkInterfaceArgs;
 * import com.pulumi.gcp.compute.MachineImage;
 * import com.pulumi.gcp.compute.MachineImageArgs;
 * import java.util.List;
 * import java.util.ArrayList;
 * import java.util.Map;
 * import java.io.File;
 * import java.nio.file.Files;
 * import java.nio.file.Paths;
 * public class App {
 *     public static void main(String[] args) {
 *         Pulumi.run(App::stack);
 *     }
 *     public static void stack(Context ctx) {
 *         var vm = new Instance("vm", InstanceArgs.builder()
 *             .name("my-vm")
 *             .machineType("e2-medium")
 *             .bootDisk(InstanceBootDiskArgs.builder()
 *                 .initializeParams(InstanceBootDiskInitializeParamsArgs.builder()
 *                     .image("debian-cloud/debian-11")
 *                     .build())
 *                 .build())
 *             .networkInterfaces(InstanceNetworkInterfaceArgs.builder()
 *                 .network("default")
 *                 .build())
 *             .build());
 *         var image = new MachineImage("image", MachineImageArgs.builder()
 *             .name("my-image")
 *             .sourceInstance(vm.selfLink())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   vm:
 *     type: gcp:compute:Instance
 *     properties:
 *       name: my-vm
 *       machineType: e2-medium
 *       bootDisk:
 *         initializeParams:
 *           image: debian-cloud/debian-11
 *       networkInterfaces:
 *         - network: default
 *   image:
 *     type: gcp:compute:MachineImage
 *     properties:
 *       name: my-image
 *       sourceInstance: ${vm.selfLink}
 * ```
 * 
 * ### Compute Machine Image Kms
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const vm = new gcp.compute.Instance("vm", {
 *     name: "my-vm",
 *     machineType: "e2-medium",
 *     bootDisk: {
 *         initializeParams: {
 *             image: "debian-cloud/debian-11",
 *         },
 *     },
 *     networkInterfaces: [{
 *         network: "default",
 *     }],
 * });
 * const keyRing = new gcp.kms.KeyRing("key_ring", {
 *     name: "keyring",
 *     location: "us",
 * });
 * const cryptoKey = new gcp.kms.CryptoKey("crypto_key", {
 *     name: "key",
 *     keyRing: keyRing.id,
 * });
 * const image = new gcp.compute.MachineImage("image", {
 *     name: "my-image",
 *     sourceInstance: vm.selfLink,
 *     machineImageEncryptionKey: {
 *         kmsKeyName: cryptoKey.id,
 *     },
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * vm = gcp.compute.Instance("vm",
 *     name="my-vm",
 *     machine_type="e2-medium",
 *     boot_disk=gcp.compute.InstanceBootDiskArgs(
 *         initialize_params=gcp.compute.InstanceBootDiskInitializeParamsArgs(
 *             image="debian-cloud/debian-11",
 *         ),
 *     ),
 *     network_interfaces=[gcp.compute.InstanceNetworkInterfaceArgs(
 *         network="default",
 *     )])
 * key_ring = gcp.kms.KeyRing("key_ring",
 *     name="keyring",
 *     location="us")
 * crypto_key = gcp.kms.CryptoKey("crypto_key",
 *     name="key",
 *     key_ring=key_ring.id)
 * image = gcp.compute.MachineImage("image",
 *     name="my-image",
 *     source_instance=vm.self_link,
 *     machine_image_encryption_key=gcp.compute.MachineImageMachineImageEncryptionKeyArgs(
 *         kms_key_name=crypto_key.id,
 *     ))
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var vm = new Gcp.Compute.Instance("vm", new()
 *     {
 *         Name = "my-vm",
 *         MachineType = "e2-medium",
 *         BootDisk = new Gcp.Compute.Inputs.InstanceBootDiskArgs
 *         {
 *             InitializeParams = new Gcp.Compute.Inputs.InstanceBootDiskInitializeParamsArgs
 *             {
 *                 Image = "debian-cloud/debian-11",
 *             },
 *         },
 *         NetworkInterfaces = new[]
 *         {
 *             new Gcp.Compute.Inputs.InstanceNetworkInterfaceArgs
 *             {
 *                 Network = "default",
 *             },
 *         },
 *     });
 *     var keyRing = new Gcp.Kms.KeyRing("key_ring", new()
 *     {
 *         Name = "keyring",
 *         Location = "us",
 *     });
 *     var cryptoKey = new Gcp.Kms.CryptoKey("crypto_key", new()
 *     {
 *         Name = "key",
 *         KeyRing = keyRing.Id,
 *     });
 *     var image = new Gcp.Compute.MachineImage("image", new()
 *     {
 *         Name = "my-image",
 *         SourceInstance = vm.SelfLink,
 *         MachineImageEncryptionKey = new Gcp.Compute.Inputs.MachineImageMachineImageEncryptionKeyArgs
 *         {
 *             KmsKeyName = cryptoKey.Id,
 *         },
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/kms"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		vm, err := compute.NewInstance(ctx, "vm", &compute.InstanceArgs{
 * 			Name:        pulumi.String("my-vm"),
 * 			MachineType: pulumi.String("e2-medium"),
 * 			BootDisk: &compute.InstanceBootDiskArgs{
 * 				InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
 * 					Image: pulumi.String("debian-cloud/debian-11"),
 * 				},
 * 			},
 * 			NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
 * 				&compute.InstanceNetworkInterfaceArgs{
 * 					Network: pulumi.String("default"),
 * 				},
 * 			},
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		keyRing, err := kms.NewKeyRing(ctx, "key_ring", &kms.KeyRingArgs{
 * 			Name:     pulumi.String("keyring"),
 * 			Location: pulumi.String("us"),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		cryptoKey, err := kms.NewCryptoKey(ctx, "crypto_key", &kms.CryptoKeyArgs{
 * 			Name:    pulumi.String("key"),
 * 			KeyRing: keyRing.ID(),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewMachineImage(ctx, "image", &compute.MachineImageArgs{
 * 			Name:           pulumi.String("my-image"),
 * 			SourceInstance: vm.SelfLink,
 * 			MachineImageEncryptionKey: &compute.MachineImageMachineImageEncryptionKeyArgs{
 * 				KmsKeyName: cryptoKey.ID(),
 * 			},
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		return nil
 * 	})
 * }
 * ```
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.gcp.compute.Instance;
 * import com.pulumi.gcp.compute.InstanceArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceBootDiskArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceBootDiskInitializeParamsArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceNetworkInterfaceArgs;
 * import com.pulumi.gcp.kms.KeyRing;
 * import com.pulumi.gcp.kms.KeyRingArgs;
 * import com.pulumi.gcp.kms.CryptoKey;
 * import com.pulumi.gcp.kms.CryptoKeyArgs;
 * import com.pulumi.gcp.compute.MachineImage;
 * import com.pulumi.gcp.compute.MachineImageArgs;
 * import com.pulumi.gcp.compute.inputs.MachineImageMachineImageEncryptionKeyArgs;
 * import java.util.List;
 * import java.util.ArrayList;
 * import java.util.Map;
 * import java.io.File;
 * import java.nio.file.Files;
 * import java.nio.file.Paths;
 * public class App {
 *     public static void main(String[] args) {
 *         Pulumi.run(App::stack);
 *     }
 *     public static void stack(Context ctx) {
 *         var vm = new Instance("vm", InstanceArgs.builder()
 *             .name("my-vm")
 *             .machineType("e2-medium")
 *             .bootDisk(InstanceBootDiskArgs.builder()
 *                 .initializeParams(InstanceBootDiskInitializeParamsArgs.builder()
 *                     .image("debian-cloud/debian-11")
 *                     .build())
 *                 .build())
 *             .networkInterfaces(InstanceNetworkInterfaceArgs.builder()
 *                 .network("default")
 *                 .build())
 *             .build());
 *         var keyRing = new KeyRing("keyRing", KeyRingArgs.builder()
 *             .name("keyring")
 *             .location("us")
 *             .build());
 *         var cryptoKey = new CryptoKey("cryptoKey", CryptoKeyArgs.builder()
 *             .name("key")
 *             .keyRing(keyRing.id())
 *             .build());
 *         var image = new MachineImage("image", MachineImageArgs.builder()
 *             .name("my-image")
 *             .sourceInstance(vm.selfLink())
 *             .machineImageEncryptionKey(MachineImageMachineImageEncryptionKeyArgs.builder()
 *                 .kmsKeyName(cryptoKey.id())
 *                 .build())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   vm:
 *     type: gcp:compute:Instance
 *     properties:
 *       name: my-vm
 *       machineType: e2-medium
 *       bootDisk:
 *         initializeParams:
 *           image: debian-cloud/debian-11
 *       networkInterfaces:
 *         - network: default
 *   image:
 *     type: gcp:compute:MachineImage
 *     properties:
 *       name: my-image
 *       sourceInstance: ${vm.selfLink}
 *       machineImageEncryptionKey:
 *         kmsKeyName: ${cryptoKey.id}
 *   cryptoKey:
 *     type: gcp:kms:CryptoKey
 *     name: crypto_key
 *     properties:
 *       name: key
 *       keyRing: ${keyRing.id}
 *   keyRing:
 *     type: gcp:kms:KeyRing
 *     name: key_ring
 *     properties:
 *       name: keyring
 *       location: us
 * ```
 * 
 * ## Import
 * MachineImage can be imported using any of these accepted formats:
 * * `projects/{{project}}/global/machineImages/{{name}}`
 * * `{{project}}/{{name}}`
 * * `{{name}}`
 * When using the `pulumi import` command, MachineImage can be imported using one of the formats above. For example:
 * ```sh
 * $ pulumi import gcp:compute/machineImage:MachineImage default projects/{{project}}/global/machineImages/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/machineImage:MachineImage default {{project}}/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/machineImage:MachineImage default {{name}}
 * ```
 */
public class MachineImage internal constructor(
    override val javaResource: com.pulumi.gcp.compute.MachineImage,
) : KotlinCustomResource(javaResource, MachineImageMapper) {
    /**
     * A text description of the resource.
     */
    public val description: Output?
        get() = javaResource.description().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * Specify this to create an application consistent machine image by informing the OS to prepare for the snapshot process.
     * Currently only supported on Windows instances using the Volume Shadow Copy Service (VSS).
     */
    public val guestFlush: Output?
        get() = javaResource.guestFlush().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * Encrypts the machine image using a customer-supplied encryption key.
     * After you encrypt a machine image with a customer-supplied key, you must
     * provide the same key if you use the machine image later (e.g. to create a
     * instance from the image)
     * Structure is documented below.
     */
    public val machineImageEncryptionKey: Output?
        get() = javaResource.machineImageEncryptionKey().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.let({ args0 -> toKotlin(args0) })
            }).orElse(null)
        })

    /**
     * Name of the resource.
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * The ID of the project in which the resource belongs.
     * If it is not provided, the provider project is used.
     */
    public val project: Output
        get() = javaResource.project().applyValue({ args0 -> args0 })

    /**
     * The URI of the created resource.
     */
    public val selfLink: Output
        get() = javaResource.selfLink().applyValue({ args0 -> args0 })

    /**
     * The source instance used to create the machine image. You can provide this as a partial or full URL to the resource.
     * - - -
     */
    public val sourceInstance: Output
        get() = javaResource.sourceInstance().applyValue({ args0 -> args0 })

    /**
     * The regional or multi-regional Cloud Storage bucket location where the machine image is stored.
     */
    public val storageLocations: Output>
        get() = javaResource.storageLocations().applyValue({ args0 -> args0.map({ args0 -> args0 }) })
}

public object MachineImageMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.gcp.compute.MachineImage::class == javaResource::class

    override fun map(javaResource: Resource): MachineImage = MachineImage(
        javaResource as
            com.pulumi.gcp.compute.MachineImage,
    )
}

/**
 * @see [MachineImage].
 * @param name The _unique_ name of the resulting resource.
 * @param block Builder for [MachineImage].
 */
public suspend fun machineImage(
    name: String,
    block: suspend MachineImageResourceBuilder.() -> Unit,
): MachineImage {
    val builder = MachineImageResourceBuilder()
    builder.name(name)
    block(builder)
    return builder.build()
}

/**
 * @see [MachineImage].
 * @param name The _unique_ name of the resulting resource.
 */
public fun machineImage(name: String): MachineImage {
    val builder = MachineImageResourceBuilder()
    builder.name(name)
    return builder.build()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy