UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

384 lines • 17.1 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.Instance = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * Provides an EC2 instance resource. This allows instances to be created, updated, and deleted. * * ## Example Usage * * ### Basic example using AMI lookup * * Using a data source * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const ubuntu = aws.ec2.getAmi({ * mostRecent: true, * filters: [ * { * name: "name", * values: ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"], * }, * { * name: "virtualization-type", * values: ["hvm"], * }, * ], * owners: ["099720109477"], * }); * const example = new aws.ec2.Instance("example", { * ami: ubuntu.then(ubuntu => ubuntu.id), * instanceType: aws.ec2.InstanceType.T3_Micro, * tags: { * Name: "HelloWorld", * }, * }); * ``` * * Using AWS Systems Manager Parameter Store * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.ec2.Instance("example", { * ami: "resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64", * instanceType: aws.ec2.InstanceType.T3_Micro, * tags: { * Name: "HelloWorld", * }, * }); * ``` * * ### Spot instance example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = aws.ec2.getAmi({ * mostRecent: true, * owners: ["amazon"], * filters: [ * { * name: "architecture", * values: ["arm64"], * }, * { * name: "name", * values: ["al2023-ami-2023*"], * }, * ], * }); * const exampleInstance = new aws.ec2.Instance("example", { * ami: example.then(example => example.id), * instanceMarketOptions: { * marketType: "spot", * spotOptions: { * maxPrice: "0.0031", * }, * }, * instanceType: aws.ec2.InstanceType.T4g_Nano, * tags: { * Name: "test-spot", * }, * }); * ``` * * ### Network and credit specification example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const myVpc = new aws.ec2.Vpc("my_vpc", { * cidrBlock: "172.16.0.0/16", * tags: { * Name: "tf-example", * }, * }); * const mySubnet = new aws.ec2.Subnet("my_subnet", { * vpcId: myVpc.id, * cidrBlock: "172.16.10.0/24", * availabilityZone: "us-west-2a", * tags: { * Name: "tf-example", * }, * }); * const example = new aws.ec2.NetworkInterface("example", { * subnetId: mySubnet.id, * privateIps: ["172.16.10.100"], * tags: { * Name: "primary_network_interface", * }, * }); * const exampleInstance = new aws.ec2.Instance("example", { * ami: "ami-005e54dee72cc1d00", * instanceType: aws.ec2.InstanceType.T2_Micro, * primaryNetworkInterface: { * networkInterfaceId: example.id, * }, * creditSpecification: { * cpuCredits: "unlimited", * }, * }); * ``` * * ### CPU options example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.ec2.Vpc("example", { * cidrBlock: "172.16.0.0/16", * tags: { * Name: "tf-example", * }, * }); * const exampleSubnet = new aws.ec2.Subnet("example", { * vpcId: example.id, * cidrBlock: "172.16.10.0/24", * availabilityZone: "us-east-2a", * tags: { * Name: "tf-example", * }, * }); * const amzn_linux_2023_ami = aws.ec2.getAmi({ * mostRecent: true, * owners: ["amazon"], * filters: [{ * name: "name", * values: ["al2023-ami-2023.*-x86_64"], * }], * }); * const exampleInstance = new aws.ec2.Instance("example", { * ami: amzn_linux_2023_ami.then(amzn_linux_2023_ami => amzn_linux_2023_ami.id), * instanceType: aws.ec2.InstanceType.C6a_2XLarge, * subnetId: exampleSubnet.id, * cpuOptions: { * coreCount: 2, * threadsPerCore: 2, * }, * tags: { * Name: "tf-example", * }, * }); * ``` * * ### Host resource group or License Manager registered AMI example * * A host resource group is a collection of Dedicated Hosts that you can manage as a single entity. As you launch instances, License Manager allocates the hosts and launches instances on them based on the settings that you configured. You can add existing Dedicated Hosts to a host resource group and take advantage of automated host management through License Manager. * * > **NOTE:** A dedicated host is automatically associated with a License Manager host resource group if **Allocate hosts automatically** is enabled. Otherwise, use the `hostResourceGroupArn` argument to explicitly associate the instance with the host resource group. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const _this = new aws.ec2.Instance("this", { * ami: "ami-0dcc1e21636832c5d", * instanceType: aws.ec2.InstanceType.M5_Large, * hostResourceGroupArn: "arn:aws:resource-groups:us-west-2:123456789012:group/win-testhost", * tenancy: "host", * }); * ``` * * ## Tag Guide * * These are the five types of tags you might encounter relative to an `aws.ec2.Instance`: * * 1. **Instance tags**: Applied to instances but not to `ebsBlockDevice` and `rootBlockDevice` volumes. * 2. **Default tags**: Applied to the instance and to `ebsBlockDevice` and `rootBlockDevice` volumes. * 3. **Volume tags**: Applied during creation to `ebsBlockDevice` and `rootBlockDevice` volumes. * 4. **Root block device tags**: Applied only to the `rootBlockDevice` volume. These conflict with `volumeTags`. * 5. **EBS block device tags**: Applied only to the specific `ebsBlockDevice` volume you configure them for and cannot be updated. These conflict with `volumeTags`. * * Do not use `volumeTags` if you plan to manage block device tags outside the `aws.ec2.Instance` configuration, such as using `tags` in an `aws.ebs.Volume` resource attached via `aws.ec2.VolumeAttachment`. Doing so will result in resource cycling and inconsistent behavior. * * ## Import * * ### Identity Schema * * #### Required * * * `id` - (String) ID of the instance. * * #### Optional * * * `account_id` (String) AWS Account where this resource is managed. * * * `region` (String) Region where this resource is managed. * * Using `pulumi import`, import instances using the `id`. For example: * * console * * % pulumi import aws_instance.web i-12345678 */ class Instance extends pulumi.CustomResource { /** * Get an existing Instance resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, state, opts) { return new Instance(name, state, { ...opts, id: id }); } /** * Returns true if the given object is an instance of Instance. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === Instance.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["ami"] = state?.ami; resourceInputs["arn"] = state?.arn; resourceInputs["associatePublicIpAddress"] = state?.associatePublicIpAddress; resourceInputs["availabilityZone"] = state?.availabilityZone; resourceInputs["capacityReservationSpecification"] = state?.capacityReservationSpecification; resourceInputs["cpuOptions"] = state?.cpuOptions; resourceInputs["creditSpecification"] = state?.creditSpecification; resourceInputs["disableApiStop"] = state?.disableApiStop; resourceInputs["disableApiTermination"] = state?.disableApiTermination; resourceInputs["ebsBlockDevices"] = state?.ebsBlockDevices; resourceInputs["ebsOptimized"] = state?.ebsOptimized; resourceInputs["enablePrimaryIpv6"] = state?.enablePrimaryIpv6; resourceInputs["enclaveOptions"] = state?.enclaveOptions; resourceInputs["ephemeralBlockDevices"] = state?.ephemeralBlockDevices; resourceInputs["forceDestroy"] = state?.forceDestroy; resourceInputs["getPasswordData"] = state?.getPasswordData; resourceInputs["hibernation"] = state?.hibernation; resourceInputs["hostId"] = state?.hostId; resourceInputs["hostResourceGroupArn"] = state?.hostResourceGroupArn; resourceInputs["iamInstanceProfile"] = state?.iamInstanceProfile; resourceInputs["instanceInitiatedShutdownBehavior"] = state?.instanceInitiatedShutdownBehavior; resourceInputs["instanceLifecycle"] = state?.instanceLifecycle; resourceInputs["instanceMarketOptions"] = state?.instanceMarketOptions; resourceInputs["instanceState"] = state?.instanceState; resourceInputs["instanceType"] = state?.instanceType; resourceInputs["ipv6AddressCount"] = state?.ipv6AddressCount; resourceInputs["ipv6Addresses"] = state?.ipv6Addresses; resourceInputs["keyName"] = state?.keyName; resourceInputs["launchTemplate"] = state?.launchTemplate; resourceInputs["maintenanceOptions"] = state?.maintenanceOptions; resourceInputs["metadataOptions"] = state?.metadataOptions; resourceInputs["monitoring"] = state?.monitoring; resourceInputs["networkInterfaces"] = state?.networkInterfaces; resourceInputs["outpostArn"] = state?.outpostArn; resourceInputs["passwordData"] = state?.passwordData; resourceInputs["placementGroup"] = state?.placementGroup; resourceInputs["placementGroupId"] = state?.placementGroupId; resourceInputs["placementPartitionNumber"] = state?.placementPartitionNumber; resourceInputs["primaryNetworkInterface"] = state?.primaryNetworkInterface; resourceInputs["primaryNetworkInterfaceId"] = state?.primaryNetworkInterfaceId; resourceInputs["privateDns"] = state?.privateDns; resourceInputs["privateDnsNameOptions"] = state?.privateDnsNameOptions; resourceInputs["privateIp"] = state?.privateIp; resourceInputs["publicDns"] = state?.publicDns; resourceInputs["publicIp"] = state?.publicIp; resourceInputs["region"] = state?.region; resourceInputs["rootBlockDevice"] = state?.rootBlockDevice; resourceInputs["secondaryPrivateIps"] = state?.secondaryPrivateIps; resourceInputs["securityGroups"] = state?.securityGroups; resourceInputs["sourceDestCheck"] = state?.sourceDestCheck; resourceInputs["spotInstanceRequestId"] = state?.spotInstanceRequestId; resourceInputs["subnetId"] = state?.subnetId; resourceInputs["tags"] = state?.tags; resourceInputs["tagsAll"] = state?.tagsAll; resourceInputs["tenancy"] = state?.tenancy; resourceInputs["userData"] = state?.userData; resourceInputs["userDataBase64"] = state?.userDataBase64; resourceInputs["userDataReplaceOnChange"] = state?.userDataReplaceOnChange; resourceInputs["volumeTags"] = state?.volumeTags; resourceInputs["vpcSecurityGroupIds"] = state?.vpcSecurityGroupIds; } else { const args = argsOrState; resourceInputs["ami"] = args?.ami; resourceInputs["associatePublicIpAddress"] = args?.associatePublicIpAddress; resourceInputs["availabilityZone"] = args?.availabilityZone; resourceInputs["capacityReservationSpecification"] = args?.capacityReservationSpecification; resourceInputs["cpuOptions"] = args?.cpuOptions; resourceInputs["creditSpecification"] = args?.creditSpecification; resourceInputs["disableApiStop"] = args?.disableApiStop; resourceInputs["disableApiTermination"] = args?.disableApiTermination; resourceInputs["ebsBlockDevices"] = args?.ebsBlockDevices; resourceInputs["ebsOptimized"] = args?.ebsOptimized; resourceInputs["enablePrimaryIpv6"] = args?.enablePrimaryIpv6; resourceInputs["enclaveOptions"] = args?.enclaveOptions; resourceInputs["ephemeralBlockDevices"] = args?.ephemeralBlockDevices; resourceInputs["forceDestroy"] = args?.forceDestroy; resourceInputs["getPasswordData"] = args?.getPasswordData; resourceInputs["hibernation"] = args?.hibernation; resourceInputs["hostId"] = args?.hostId; resourceInputs["hostResourceGroupArn"] = args?.hostResourceGroupArn; resourceInputs["iamInstanceProfile"] = args?.iamInstanceProfile; resourceInputs["instanceInitiatedShutdownBehavior"] = args?.instanceInitiatedShutdownBehavior; resourceInputs["instanceMarketOptions"] = args?.instanceMarketOptions; resourceInputs["instanceType"] = args?.instanceType; resourceInputs["ipv6AddressCount"] = args?.ipv6AddressCount; resourceInputs["ipv6Addresses"] = args?.ipv6Addresses; resourceInputs["keyName"] = args?.keyName; resourceInputs["launchTemplate"] = args?.launchTemplate; resourceInputs["maintenanceOptions"] = args?.maintenanceOptions; resourceInputs["metadataOptions"] = args?.metadataOptions; resourceInputs["monitoring"] = args?.monitoring; resourceInputs["networkInterfaces"] = args?.networkInterfaces; resourceInputs["placementGroup"] = args?.placementGroup; resourceInputs["placementGroupId"] = args?.placementGroupId; resourceInputs["placementPartitionNumber"] = args?.placementPartitionNumber; resourceInputs["primaryNetworkInterface"] = args?.primaryNetworkInterface; resourceInputs["privateDnsNameOptions"] = args?.privateDnsNameOptions; resourceInputs["privateIp"] = args?.privateIp; resourceInputs["region"] = args?.region; resourceInputs["rootBlockDevice"] = args?.rootBlockDevice; resourceInputs["secondaryPrivateIps"] = args?.secondaryPrivateIps; resourceInputs["securityGroups"] = args?.securityGroups; resourceInputs["sourceDestCheck"] = args?.sourceDestCheck; resourceInputs["subnetId"] = args?.subnetId; resourceInputs["tags"] = args?.tags; resourceInputs["tenancy"] = args?.tenancy; resourceInputs["userData"] = args?.userData; resourceInputs["userDataBase64"] = args?.userDataBase64; resourceInputs["userDataReplaceOnChange"] = args?.userDataReplaceOnChange; resourceInputs["volumeTags"] = args?.volumeTags; resourceInputs["vpcSecurityGroupIds"] = args?.vpcSecurityGroupIds; resourceInputs["arn"] = undefined /*out*/; resourceInputs["instanceLifecycle"] = undefined /*out*/; resourceInputs["instanceState"] = undefined /*out*/; resourceInputs["outpostArn"] = undefined /*out*/; resourceInputs["passwordData"] = undefined /*out*/; resourceInputs["primaryNetworkInterfaceId"] = undefined /*out*/; resourceInputs["privateDns"] = undefined /*out*/; resourceInputs["publicDns"] = undefined /*out*/; resourceInputs["publicIp"] = undefined /*out*/; resourceInputs["spotInstanceRequestId"] = undefined /*out*/; resourceInputs["tagsAll"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(Instance.__pulumiType, name, resourceInputs, opts); } } exports.Instance = Instance; /** @internal */ Instance.__pulumiType = 'aws:ec2/instance:Instance'; //# sourceMappingURL=instance.js.map