Skip to content

Resource: awsLightsailInstance

Provides a Lightsail Instance. Amazon Lightsail is a service to provide easy virtual private servers with custom software already setup. See What is Amazon Lightsail? for more information.

\~> Note: Lightsail is currently only supported in a limited number of AWS Regions, please see "Regions and Availability Zones in Amazon Lightsail" for more details

Example Usage

Basic Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lightsailInstance.LightsailInstance(this, "gitlab_test", {
  availabilityZone: "us-east-1b",
  blueprintId: "amazon_linux_2",
  bundleId: "nano_1_0",
  keyPairName: "some_key_name",
  name: "custom_gitlab",
  tags: {
    foo: "bar",
  },
});

Example With User Data

Lightsail user data is handled differently than ec2 user data. Lightsail user data only accepts a single lined string. The below example shows installing apache and creating the index page.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lightsailInstance.LightsailInstance(this, "custom", {
  availabilityZone: "us-east-1b",
  blueprintId: "amazon_linux_2",
  bundleId: "nano_1_0",
  name: "custom",
  userData:
    "sudo yum install -y httpd && sudo systemctl start httpd && sudo systemctl enable httpd && echo '<h1>Deployed via Terraform</h1>' | sudo tee /var/www/html/index.html",
});

Enable Auto Snapshots

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.lightsailInstance.LightsailInstance(this, "test", {
  addOn: {
    snapshotTime: "06:00",
    status: "Enabled",
    type: "AutoSnapshot",
  },
  availabilityZone: "us-east-1b",
  blueprintId: "amazon_linux_2",
  bundleId: "nano_1_0",
  name: "custom_instance",
  tags: {
    foo: "bar",
  },
});

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the Lightsail Instance. Names be unique within each AWS Region in your Lightsail account.
  • availabilityZone - (Required) The Availability Zone in which to create your instance (see list below)
  • blueprintId - (Required) The ID for a virtual private server image. A list of available blueprint IDs can be obtained using the AWS CLI command: awsLightsailGetBlueprints
  • bundleId - (Required) The bundle of specification information (see list below)
  • keyPairName - (Optional) The name of your key pair. Created in the Lightsail console (cannot use awsKeyPair at this time)
  • userData - (Optional) Single lined launch script as a string to configure server with additional user data
  • ipAddressType - (Optional) The IP address type of the Lightsail Instance. Valid Values: dualstack | ipv4.
  • addOn - (Optional) The add on configuration for the instance. Detailed below.
  • tags - (Optional) A map of tags to assign to the resource. To create a key-only tag, use an empty string as the value. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

addOn

Defines the add on configuration for the instance. The addOn configuration block supports the following arguments:

  • type - (Required) The add-on type. There is currently only one valid type autoSnapshot.
  • snapshotTime - (Required) The daily time when an automatic snapshot will be created. Must be in HH:00 format, and in an hourly increment and specified in Coordinated Universal Time (UTC). The snapshot will be automatically created between the time specified and up to 45 minutes after.
  • status - (Required) The status of the add on. Valid Values: enabled, disabled.

Availability Zones

Lightsail currently supports the following Availability Zones (e.g., usEast1A):

  • apNortheast1{a,c,d}
  • apNortheast2{a,c}
  • apSouth1{a,b}
  • apSoutheast1{a,b,c}
  • apSoutheast2{a,b,c}
  • caCentral1{a,b}
  • euCentral1{a,b,c}
  • euWest1{a,b,c}
  • euWest2{a,b,c}
  • euWest3{a,b,c}
  • usEast1{a,b,c,d,e,f}
  • usEast2{a,b,c}
  • usWest2{a,b,c}

Bundles

Lightsail currently supports the following Bundle IDs (e.g., an instance in apNortheast1 would use small20):

Prefix

A Bundle ID starts with one of the below size prefixes:

  • nano
  • micro
  • small
  • medium
  • large
  • xlarge
  • 2Xlarge

Suffix

A Bundle ID ends with one of the following suffixes depending on Availability Zone:

  • ap-northeast-1: 2_0
  • ap-northeast-2: 2_0
  • ap-south-1: 2_1
  • ap-southeast-1: 2_0
  • ap-southeast-2: 2_2
  • ca-central-1: 2_0
  • eu-central-1: 2_0
  • eu-west-1: 2_0
  • eu-west-2: 2_0
  • eu-west-3: 2_0
  • us-east-1: 2_0
  • us-east-2: 2_0
  • us-west-2: 2_0

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - The ARN of the Lightsail instance (matches arn).
  • arn - The ARN of the Lightsail instance (matches id).
  • createdAt - The timestamp when the instance was created.
  • cpuCount - The number of vCPUs the instance has.
  • ramSize - The amount of RAM in GB on the instance (e.g., 1.0).
  • ipv6Address - (Deprecated) The first IPv6 address of the Lightsail instance. Use ipv6Addresses attribute instead.
  • ipv6Addresses - List of IPv6 addresses for the Lightsail instance.
  • privateIpAddress - The private IP address of the instance.
  • publicIpAddress - The public IP address of the instance.
  • isStaticIp - A Boolean value indicating whether this instance has a static IP assigned to it.
  • username - The user name for connecting to the instance (e.g., ec2-user).
  • tagsAll - A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

Lightsail Instances can be imported using their name, e.g.,

$ terraform import aws_lightsail_instance.gitlab_test 'custom_gitlab'