2015-08-30 06:35:45 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/hashcode"
|
2017-03-15 16:45:42 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
2015-08-30 06:35:45 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
2017-03-14 21:15:19 +01:00
|
|
|
const (
|
2017-03-29 19:06:17 +02:00
|
|
|
AWSAMIRetryTimeout = 20 * time.Minute
|
2017-03-22 14:27:23 +01:00
|
|
|
AWSAMIDeleteRetryTimeout = 20 * time.Minute
|
|
|
|
AWSAMIRetryDelay = 5 * time.Second
|
|
|
|
AWSAMIRetryMinTimeout = 3 * time.Second
|
2017-03-14 21:15:19 +01:00
|
|
|
)
|
|
|
|
|
2015-08-30 06:35:45 +02:00
|
|
|
func resourceAwsAmi() *schema.Resource {
|
|
|
|
// Our schema is shared also with aws_ami_copy and aws_ami_from_instance
|
|
|
|
resourceSchema := resourceAwsAmiCommonSchema(false)
|
|
|
|
|
|
|
|
return &schema.Resource{
|
|
|
|
Create: resourceAwsAmiCreate,
|
|
|
|
|
|
|
|
Schema: resourceSchema,
|
|
|
|
|
|
|
|
// The Read, Update and Delete operations are shared with aws_ami_copy
|
|
|
|
// and aws_ami_from_instance, since they differ only in how the image
|
|
|
|
// is created.
|
|
|
|
Read: resourceAwsAmiRead,
|
|
|
|
Update: resourceAwsAmiUpdate,
|
|
|
|
Delete: resourceAwsAmiDelete,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsAmiCreate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
client := meta.(*AWSClient).ec2conn
|
|
|
|
|
|
|
|
req := &ec2.RegisterImageInput{
|
|
|
|
Name: aws.String(d.Get("name").(string)),
|
|
|
|
Description: aws.String(d.Get("description").(string)),
|
|
|
|
Architecture: aws.String(d.Get("architecture").(string)),
|
|
|
|
ImageLocation: aws.String(d.Get("image_location").(string)),
|
|
|
|
RootDeviceName: aws.String(d.Get("root_device_name").(string)),
|
|
|
|
SriovNetSupport: aws.String(d.Get("sriov_net_support").(string)),
|
|
|
|
VirtualizationType: aws.String(d.Get("virtualization_type").(string)),
|
|
|
|
}
|
|
|
|
|
|
|
|
if kernelId := d.Get("kernel_id").(string); kernelId != "" {
|
|
|
|
req.KernelId = aws.String(kernelId)
|
|
|
|
}
|
|
|
|
if ramdiskId := d.Get("ramdisk_id").(string); ramdiskId != "" {
|
|
|
|
req.RamdiskId = aws.String(ramdiskId)
|
|
|
|
}
|
|
|
|
|
|
|
|
ebsBlockDevsSet := d.Get("ebs_block_device").(*schema.Set)
|
|
|
|
ephemeralBlockDevsSet := d.Get("ephemeral_block_device").(*schema.Set)
|
|
|
|
for _, ebsBlockDevI := range ebsBlockDevsSet.List() {
|
|
|
|
ebsBlockDev := ebsBlockDevI.(map[string]interface{})
|
|
|
|
blockDev := &ec2.BlockDeviceMapping{
|
|
|
|
DeviceName: aws.String(ebsBlockDev["device_name"].(string)),
|
|
|
|
Ebs: &ec2.EbsBlockDevice{
|
|
|
|
DeleteOnTermination: aws.Bool(ebsBlockDev["delete_on_termination"].(bool)),
|
2017-02-10 15:41:45 +01:00
|
|
|
VolumeType: aws.String(ebsBlockDev["volume_type"].(string)),
|
2015-08-30 06:35:45 +02:00
|
|
|
},
|
|
|
|
}
|
2017-02-10 02:30:26 +01:00
|
|
|
if iops, ok := ebsBlockDev["iops"]; ok {
|
|
|
|
if iop := iops.(int); iop != 0 {
|
|
|
|
blockDev.Ebs.Iops = aws.Int64(int64(iop))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if size, ok := ebsBlockDev["volume_size"]; ok {
|
|
|
|
if s := size.(int); s != 0 {
|
|
|
|
blockDev.Ebs.VolumeSize = aws.Int64(int64(s))
|
|
|
|
}
|
2015-08-30 06:35:45 +02:00
|
|
|
}
|
|
|
|
encrypted := ebsBlockDev["encrypted"].(bool)
|
|
|
|
if snapshotId := ebsBlockDev["snapshot_id"].(string); snapshotId != "" {
|
|
|
|
blockDev.Ebs.SnapshotId = aws.String(snapshotId)
|
|
|
|
if encrypted {
|
|
|
|
return errors.New("can't set both 'snapshot_id' and 'encrypted'")
|
|
|
|
}
|
|
|
|
} else if encrypted {
|
|
|
|
blockDev.Ebs.Encrypted = aws.Bool(true)
|
|
|
|
}
|
|
|
|
req.BlockDeviceMappings = append(req.BlockDeviceMappings, blockDev)
|
|
|
|
}
|
|
|
|
for _, ephemeralBlockDevI := range ephemeralBlockDevsSet.List() {
|
|
|
|
ephemeralBlockDev := ephemeralBlockDevI.(map[string]interface{})
|
|
|
|
blockDev := &ec2.BlockDeviceMapping{
|
|
|
|
DeviceName: aws.String(ephemeralBlockDev["device_name"].(string)),
|
|
|
|
VirtualName: aws.String(ephemeralBlockDev["virtual_name"].(string)),
|
|
|
|
}
|
|
|
|
req.BlockDeviceMappings = append(req.BlockDeviceMappings, blockDev)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := client.RegisterImage(req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
id := *res.ImageId
|
|
|
|
d.SetId(id)
|
|
|
|
d.Partial(true) // make sure we record the id even if the rest of this gets interrupted
|
|
|
|
d.Set("id", id)
|
|
|
|
d.Set("manage_ebs_block_devices", false)
|
|
|
|
d.SetPartial("id")
|
|
|
|
d.SetPartial("manage_ebs_block_devices")
|
|
|
|
d.Partial(false)
|
|
|
|
|
|
|
|
_, err = resourceAwsAmiWaitForAvailable(id, client)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resourceAwsAmiUpdate(d, meta)
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
client := meta.(*AWSClient).ec2conn
|
|
|
|
id := d.Id()
|
|
|
|
|
|
|
|
req := &ec2.DescribeImagesInput{
|
|
|
|
ImageIds: []*string{aws.String(id)},
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := client.DescribeImages(req)
|
|
|
|
if err != nil {
|
2016-10-31 10:51:59 +01:00
|
|
|
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidAMIID.NotFound" {
|
|
|
|
log.Printf("[DEBUG] %s no longer exists, so we'll drop it from the state", id)
|
|
|
|
d.SetId("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-30 06:35:45 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(res.Images) != 1 {
|
|
|
|
d.SetId("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
image := res.Images[0]
|
2015-10-08 14:48:04 +02:00
|
|
|
state := *image.State
|
2015-08-30 06:35:45 +02:00
|
|
|
|
|
|
|
if state == "pending" {
|
|
|
|
// This could happen if a user manually adds an image we didn't create
|
|
|
|
// to the state. We'll wait for the image to become available
|
|
|
|
// before we continue. We should never take this branch in normal
|
|
|
|
// circumstances since we would've waited for availability during
|
|
|
|
// the "Create" step.
|
|
|
|
image, err = resourceAwsAmiWaitForAvailable(id, client)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-10-08 14:48:04 +02:00
|
|
|
state = *image.State
|
2015-08-30 06:35:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if state == "deregistered" {
|
|
|
|
d.SetId("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if state != "available" {
|
|
|
|
return fmt.Errorf("AMI has become %s", state)
|
|
|
|
}
|
|
|
|
|
|
|
|
d.Set("name", image.Name)
|
|
|
|
d.Set("description", image.Description)
|
|
|
|
d.Set("image_location", image.ImageLocation)
|
|
|
|
d.Set("architecture", image.Architecture)
|
|
|
|
d.Set("kernel_id", image.KernelId)
|
|
|
|
d.Set("ramdisk_id", image.RamdiskId)
|
|
|
|
d.Set("root_device_name", image.RootDeviceName)
|
|
|
|
d.Set("sriov_net_support", image.SriovNetSupport)
|
|
|
|
d.Set("virtualization_type", image.VirtualizationType)
|
|
|
|
|
|
|
|
var ebsBlockDevs []map[string]interface{}
|
|
|
|
var ephemeralBlockDevs []map[string]interface{}
|
|
|
|
|
|
|
|
for _, blockDev := range image.BlockDeviceMappings {
|
|
|
|
if blockDev.Ebs != nil {
|
|
|
|
ebsBlockDev := map[string]interface{}{
|
2015-10-08 14:48:04 +02:00
|
|
|
"device_name": *blockDev.DeviceName,
|
|
|
|
"delete_on_termination": *blockDev.Ebs.DeleteOnTermination,
|
|
|
|
"encrypted": *blockDev.Ebs.Encrypted,
|
2015-08-30 06:35:45 +02:00
|
|
|
"iops": 0,
|
2015-10-08 14:48:04 +02:00
|
|
|
"volume_size": int(*blockDev.Ebs.VolumeSize),
|
|
|
|
"volume_type": *blockDev.Ebs.VolumeType,
|
2015-08-30 06:35:45 +02:00
|
|
|
}
|
|
|
|
if blockDev.Ebs.Iops != nil {
|
2015-10-08 14:48:04 +02:00
|
|
|
ebsBlockDev["iops"] = int(*blockDev.Ebs.Iops)
|
2015-08-30 06:35:45 +02:00
|
|
|
}
|
2016-08-05 05:04:57 +02:00
|
|
|
// The snapshot ID might not be set.
|
|
|
|
if blockDev.Ebs.SnapshotId != nil {
|
|
|
|
ebsBlockDev["snapshot_id"] = *blockDev.Ebs.SnapshotId
|
|
|
|
}
|
2015-08-30 06:35:45 +02:00
|
|
|
ebsBlockDevs = append(ebsBlockDevs, ebsBlockDev)
|
|
|
|
} else {
|
|
|
|
ephemeralBlockDevs = append(ephemeralBlockDevs, map[string]interface{}{
|
2015-10-08 14:48:04 +02:00
|
|
|
"device_name": *blockDev.DeviceName,
|
|
|
|
"virtual_name": *blockDev.VirtualName,
|
2015-08-30 06:35:45 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d.Set("ebs_block_device", ebsBlockDevs)
|
|
|
|
d.Set("ephemeral_block_device", ephemeralBlockDevs)
|
|
|
|
|
|
|
|
d.Set("tags", tagsToMap(image.Tags))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsAmiUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
client := meta.(*AWSClient).ec2conn
|
|
|
|
|
|
|
|
d.Partial(true)
|
|
|
|
|
|
|
|
if err := setTags(client, d); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
d.SetPartial("tags")
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.Get("description").(string) != "" {
|
|
|
|
_, err := client.ModifyImageAttribute(&ec2.ModifyImageAttributeInput{
|
|
|
|
ImageId: aws.String(d.Id()),
|
|
|
|
Description: &ec2.AttributeValue{
|
|
|
|
Value: aws.String(d.Get("description").(string)),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
d.SetPartial("description")
|
|
|
|
}
|
|
|
|
|
|
|
|
d.Partial(false)
|
|
|
|
|
|
|
|
return resourceAwsAmiRead(d, meta)
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsAmiDelete(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
client := meta.(*AWSClient).ec2conn
|
|
|
|
|
|
|
|
req := &ec2.DeregisterImageInput{
|
|
|
|
ImageId: aws.String(d.Id()),
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := client.DeregisterImage(req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're managing the EBS snapshots then we need to delete those too.
|
|
|
|
if d.Get("manage_ebs_snapshots").(bool) {
|
|
|
|
errs := map[string]error{}
|
|
|
|
ebsBlockDevsSet := d.Get("ebs_block_device").(*schema.Set)
|
|
|
|
req := &ec2.DeleteSnapshotInput{}
|
|
|
|
for _, ebsBlockDevI := range ebsBlockDevsSet.List() {
|
|
|
|
ebsBlockDev := ebsBlockDevI.(map[string]interface{})
|
|
|
|
snapshotId := ebsBlockDev["snapshot_id"].(string)
|
|
|
|
if snapshotId != "" {
|
|
|
|
req.SnapshotId = aws.String(snapshotId)
|
|
|
|
_, err := client.DeleteSnapshot(req)
|
|
|
|
if err != nil {
|
|
|
|
errs[snapshotId] = err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(errs) > 0 {
|
|
|
|
errParts := []string{"Errors while deleting associated EBS snapshots:"}
|
|
|
|
for snapshotId, err := range errs {
|
|
|
|
errParts = append(errParts, fmt.Sprintf("%s: %s", snapshotId, err))
|
|
|
|
}
|
|
|
|
errParts = append(errParts, "These are no longer managed by Terraform and must be deleted manually.")
|
|
|
|
return errors.New(strings.Join(errParts, "\n"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 21:15:19 +01:00
|
|
|
// Verify that the image is actually removed, if not we need to wait for it to be removed
|
|
|
|
if err := resourceAwsAmiWaitForDestroy(d.Id(), client); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-08-30 06:35:45 +02:00
|
|
|
|
2017-03-14 21:15:19 +01:00
|
|
|
// No error, ami was deleted successfully
|
|
|
|
d.SetId("")
|
2015-08-30 06:35:45 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-15 16:45:42 +01:00
|
|
|
func AMIStateRefreshFunc(client *ec2.EC2, id string) resource.StateRefreshFunc {
|
|
|
|
return func() (interface{}, string, error) {
|
2017-03-15 18:06:50 +01:00
|
|
|
emptyResp := &ec2.DescribeImagesOutput{}
|
2017-03-15 16:45:42 +01:00
|
|
|
|
2017-03-15 18:06:50 +01:00
|
|
|
resp, err := client.DescribeImages(&ec2.DescribeImagesInput{ImageIds: []*string{aws.String(id)}})
|
2017-03-15 16:45:42 +01:00
|
|
|
if err != nil {
|
|
|
|
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidAMIID.NotFound" {
|
2017-03-15 18:06:50 +01:00
|
|
|
return emptyResp, "destroyed", nil
|
2017-03-15 16:45:42 +01:00
|
|
|
} else if resp != nil && len(resp.Images) == 0 {
|
2017-03-15 18:06:50 +01:00
|
|
|
return emptyResp, "destroyed", nil
|
2017-03-15 16:45:42 +01:00
|
|
|
} else {
|
2017-03-15 18:06:50 +01:00
|
|
|
return emptyResp, "", fmt.Errorf("Error on refresh: %+v", err)
|
2017-03-15 16:45:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp == nil || resp.Images == nil || len(resp.Images) == 0 {
|
2017-03-15 18:06:50 +01:00
|
|
|
return emptyResp, "destroyed", nil
|
2017-03-15 16:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// AMI is valid, so return it's state
|
|
|
|
return resp.Images[0], *resp.Images[0].State, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 21:15:19 +01:00
|
|
|
func resourceAwsAmiWaitForDestroy(id string, client *ec2.EC2) error {
|
|
|
|
log.Printf("Waiting for AMI %s to be deleted...", id)
|
|
|
|
|
2017-03-15 16:45:42 +01:00
|
|
|
stateConf := &resource.StateChangeConf{
|
|
|
|
Pending: []string{"available", "pending", "failed"},
|
|
|
|
Target: []string{"destroyed"},
|
|
|
|
Refresh: AMIStateRefreshFunc(client, id),
|
2017-03-22 14:27:23 +01:00
|
|
|
Timeout: AWSAMIDeleteRetryTimeout,
|
2017-03-15 18:06:50 +01:00
|
|
|
Delay: AWSAMIRetryDelay,
|
|
|
|
MinTimeout: AWSAMIRetryTimeout,
|
2017-03-15 16:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err := stateConf.WaitForState()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error waiting for AMI (%s) to be deleted: %v", id, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-03-14 21:15:19 +01:00
|
|
|
}
|
|
|
|
|
2015-08-30 06:35:45 +02:00
|
|
|
func resourceAwsAmiWaitForAvailable(id string, client *ec2.EC2) (*ec2.Image, error) {
|
|
|
|
log.Printf("Waiting for AMI %s to become available...", id)
|
|
|
|
|
2017-03-15 18:06:50 +01:00
|
|
|
stateConf := &resource.StateChangeConf{
|
|
|
|
Pending: []string{"pending"},
|
|
|
|
Target: []string{"available"},
|
|
|
|
Refresh: AMIStateRefreshFunc(client, id),
|
|
|
|
Timeout: AWSAMIRetryTimeout,
|
|
|
|
Delay: AWSAMIRetryDelay,
|
|
|
|
MinTimeout: AWSAMIRetryMinTimeout,
|
2015-08-30 06:35:45 +02:00
|
|
|
}
|
|
|
|
|
2017-03-15 18:06:50 +01:00
|
|
|
info, err := stateConf.WaitForState()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error waiting for AMI (%s) to be ready: %v", id, err)
|
2015-08-30 06:35:45 +02:00
|
|
|
}
|
2017-03-15 18:06:50 +01:00
|
|
|
return info.(*ec2.Image), nil
|
2015-08-30 06:35:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsAmiCommonSchema(computed bool) map[string]*schema.Schema {
|
|
|
|
// The "computed" parameter controls whether we're making
|
|
|
|
// a schema for an AMI that's been implicitly registered (aws_ami_copy, aws_ami_from_instance)
|
|
|
|
// or whether we're making a schema for an explicit registration (aws_ami).
|
|
|
|
// When set, almost every attribute is marked as "computed".
|
|
|
|
// When not set, only the "id" attribute is computed.
|
|
|
|
// "name" and "description" are never computed, since they must always
|
|
|
|
// be provided by the user.
|
|
|
|
|
|
|
|
var virtualizationTypeDefault interface{}
|
|
|
|
var deleteEbsOnTerminationDefault interface{}
|
|
|
|
var sriovNetSupportDefault interface{}
|
|
|
|
var architectureDefault interface{}
|
|
|
|
var volumeTypeDefault interface{}
|
|
|
|
if !computed {
|
|
|
|
virtualizationTypeDefault = "paravirtual"
|
|
|
|
deleteEbsOnTerminationDefault = true
|
|
|
|
sriovNetSupportDefault = "simple"
|
|
|
|
architectureDefault = "x86_64"
|
|
|
|
volumeTypeDefault = "standard"
|
|
|
|
}
|
|
|
|
|
|
|
|
return map[string]*schema.Schema{
|
2017-02-10 02:30:26 +01:00
|
|
|
"id": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"image_location": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: !computed,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"architecture": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
Default: architectureDefault,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"description": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"kernel_id": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"name": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"ramdisk_id": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"root_device_name": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"sriov_net_support": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
Default: sriovNetSupportDefault,
|
|
|
|
},
|
2017-02-10 02:30:26 +01:00
|
|
|
"virtualization_type": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
Default: virtualizationTypeDefault,
|
|
|
|
},
|
|
|
|
|
|
|
|
// The following block device attributes intentionally mimick the
|
|
|
|
// corresponding attributes on aws_instance, since they have the
|
|
|
|
// same meaning.
|
|
|
|
// However, we don't use root_block_device here because the constraint
|
|
|
|
// on which root device attributes can be overridden for an instance to
|
|
|
|
// not apply when registering an AMI.
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"ebs_block_device": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2017-02-10 02:30:26 +01:00
|
|
|
"delete_on_termination": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: !computed,
|
|
|
|
Default: deleteEbsOnTerminationDefault,
|
|
|
|
ForceNew: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
},
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"device_name": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: !computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
},
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"encrypted": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
},
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"iops": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
},
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"snapshot_id": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
},
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"volume_size": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: !computed,
|
|
|
|
},
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"volume_type": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
ForceNew: !computed,
|
|
|
|
Default: volumeTypeDefault,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
m := v.(map[string]interface{})
|
|
|
|
buf.WriteString(fmt.Sprintf("%s-", m["device_name"].(string)))
|
|
|
|
buf.WriteString(fmt.Sprintf("%s-", m["snapshot_id"].(string)))
|
|
|
|
return hashcode.String(buf.String())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"ephemeral_block_device": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2017-02-10 02:30:26 +01:00
|
|
|
"device_name": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
},
|
|
|
|
|
2017-02-10 02:30:26 +01:00
|
|
|
"virtual_name": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: !computed,
|
|
|
|
Computed: computed,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Set: func(v interface{}) int {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
m := v.(map[string]interface{})
|
|
|
|
buf.WriteString(fmt.Sprintf("%s-", m["device_name"].(string)))
|
|
|
|
buf.WriteString(fmt.Sprintf("%s-", m["virtual_name"].(string)))
|
|
|
|
return hashcode.String(buf.String())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"tags": tagsSchema(),
|
|
|
|
|
|
|
|
// Not a public attribute; used to let the aws_ami_copy and aws_ami_from_instance
|
|
|
|
// resources record that they implicitly created new EBS snapshots that we should
|
|
|
|
// now manage. Not set by aws_ami, since the snapshots used there are presumed to
|
|
|
|
// be independently managed.
|
2017-02-10 02:30:26 +01:00
|
|
|
"manage_ebs_snapshots": {
|
2015-08-30 06:35:45 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|