2014-07-14 20:10:13 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-02 17:47:37 +02:00
|
|
|
"math/rand"
|
|
|
|
"strings"
|
2014-07-14 20:10:13 +02:00
|
|
|
"testing"
|
2015-04-02 17:47:37 +02:00
|
|
|
"time"
|
2014-07-14 20:10:13 +02:00
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/aws/aws-sdk-go/service/autoscaling"
|
2016-07-16 16:13:29 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2014-07-14 20:10:13 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-06-08 01:18:14 +02:00
|
|
|
func TestAccAWSLaunchConfiguration_basic(t *testing.T) {
|
2014-07-14 20:10:13 +02:00
|
|
|
var conf autoscaling.LaunchConfiguration
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2015-06-08 01:18:14 +02:00
|
|
|
Config: testAccAWSLaunchConfigurationNoNameConfig,
|
2014-07-14 20:10:13 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.bar", &conf),
|
2015-06-08 01:18:14 +02:00
|
|
|
testAccCheckAWSLaunchConfigurationGeneratedNamePrefix(
|
|
|
|
"aws_launch_configuration.bar", "terraform-"),
|
2015-01-23 22:51:25 +01:00
|
|
|
),
|
|
|
|
},
|
2015-11-07 08:25:07 +01:00
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSLaunchConfigurationPrefixNameConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.baz", &conf),
|
|
|
|
testAccCheckAWSLaunchConfigurationGeneratedNamePrefix(
|
|
|
|
"aws_launch_configuration.baz", "baz-"),
|
|
|
|
),
|
|
|
|
},
|
2015-04-02 17:47:37 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2015-01-23 22:51:25 +01:00
|
|
|
|
2015-06-08 01:18:14 +02:00
|
|
|
func TestAccAWSLaunchConfiguration_withBlockDevices(t *testing.T) {
|
2015-04-02 17:47:37 +02:00
|
|
|
var conf autoscaling.LaunchConfiguration
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2015-01-23 22:51:25 +01:00
|
|
|
resource.TestStep{
|
2015-06-08 01:18:14 +02:00
|
|
|
Config: testAccAWSLaunchConfigurationConfig,
|
2015-01-23 22:51:25 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.bar", &conf),
|
2015-06-08 01:18:14 +02:00
|
|
|
testAccCheckAWSLaunchConfigurationAttributes(&conf),
|
2015-01-23 22:51:25 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-06-08 01:18:14 +02:00
|
|
|
"aws_launch_configuration.bar", "image_id", "ami-21f78e11"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_launch_configuration.bar", "instance_type", "m1.small"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_launch_configuration.bar", "associate_public_ip_address", "true"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_launch_configuration.bar", "spot_price", ""),
|
2014-07-14 20:10:13 +02:00
|
|
|
),
|
|
|
|
},
|
2015-04-02 17:47:37 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-06-08 01:18:14 +02:00
|
|
|
func TestAccAWSLaunchConfiguration_withSpotPrice(t *testing.T) {
|
2015-04-02 17:47:37 +02:00
|
|
|
var conf autoscaling.LaunchConfiguration
|
2015-02-27 19:15:12 +01:00
|
|
|
|
2015-04-02 17:47:37 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2015-02-27 19:15:12 +01:00
|
|
|
resource.TestStep{
|
2015-06-08 01:18:14 +02:00
|
|
|
Config: testAccAWSLaunchConfigurationWithSpotPriceConfig,
|
2015-02-27 19:15:12 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.bar", &conf),
|
2015-06-08 01:18:14 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_launch_configuration.bar", "spot_price", "0.01"),
|
2015-02-27 19:15:12 +01:00
|
|
|
),
|
|
|
|
},
|
2014-07-14 20:10:13 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-07-16 16:13:29 +02:00
|
|
|
func TestAccAWSLaunchConfiguration_withVpcClassicLink(t *testing.T) {
|
|
|
|
var vpc ec2.Vpc
|
|
|
|
var group ec2.SecurityGroup
|
|
|
|
var conf autoscaling.LaunchConfiguration
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSLaunchConfigurationConfig_withVpcClassicLink,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.foo", &conf),
|
|
|
|
testAccCheckVpcExists("aws_vpc.foo", &vpc),
|
|
|
|
testAccCheckAWSSecurityGroupExists("aws_security_group.foo", &group),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:07:47 +01:00
|
|
|
func TestAccAWSLaunchConfiguration_withIAMProfile(t *testing.T) {
|
|
|
|
var conf autoscaling.LaunchConfiguration
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSLaunchConfigurationConfig_withIAMProfile,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.bar", &conf),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-06 08:36:39 +01:00
|
|
|
func testAccCheckAWSLaunchConfigurationWithEncryption(conf *autoscaling.LaunchConfiguration) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
// Map out the block devices by name, which should be unique.
|
|
|
|
blockDevices := make(map[string]*autoscaling.BlockDeviceMapping)
|
|
|
|
for _, blockDevice := range conf.BlockDeviceMappings {
|
|
|
|
blockDevices[*blockDevice.DeviceName] = blockDevice
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the root block device exists.
|
|
|
|
if _, ok := blockDevices["/dev/sda1"]; !ok {
|
|
|
|
return fmt.Errorf("block device doesn't exist: /dev/sda1")
|
|
|
|
} else if blockDevices["/dev/sda1"].Ebs.Encrypted != nil {
|
|
|
|
return fmt.Errorf("root device should not include value for Encrypted")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the secondary block device exists.
|
|
|
|
if _, ok := blockDevices["/dev/sdb"]; !ok {
|
|
|
|
return fmt.Errorf("block device doesn't exist: /dev/sdb")
|
|
|
|
} else if !*blockDevices["/dev/sdb"].Ebs.Encrypted {
|
|
|
|
return fmt.Errorf("block device isn't encrypted as expected: /dev/sdb")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAWSLaunchConfiguration_withEncryption(t *testing.T) {
|
|
|
|
var conf autoscaling.LaunchConfiguration
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSLaunchConfigurationWithEncryption,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.baz", &conf),
|
|
|
|
|
|
|
|
testAccCheckAWSLaunchConfigurationWithEncryption(&conf),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-02 17:47:37 +02:00
|
|
|
func testAccCheckAWSLaunchConfigurationGeneratedNamePrefix(
|
|
|
|
resource, prefix string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
r, ok := s.RootModule().Resources[resource]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Resource not found")
|
|
|
|
}
|
|
|
|
name, ok := r.Primary.Attributes["name"]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Name attr not found: %#v", r.Primary.Attributes)
|
|
|
|
}
|
|
|
|
if !strings.HasPrefix(name, prefix) {
|
|
|
|
return fmt.Errorf("Name: %q, does not have prefix: %q", name, prefix)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-14 20:10:13 +02:00
|
|
|
func testAccCheckAWSLaunchConfigurationDestroy(s *terraform.State) error {
|
2014-11-21 17:58:34 +01:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
|
2014-07-14 20:10:13 +02:00
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
2014-07-14 20:10:13 +02:00
|
|
|
if rs.Type != "aws_launch_configuration" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2014-07-14 23:59:08 +02:00
|
|
|
describe, err := conn.DescribeLaunchConfigurations(
|
2015-04-16 14:10:17 +02:00
|
|
|
&autoscaling.DescribeLaunchConfigurationsInput{
|
|
|
|
LaunchConfigurationNames: []*string{aws.String(rs.Primary.ID)},
|
2014-07-14 20:10:13 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if err == nil {
|
2014-07-14 23:59:08 +02:00
|
|
|
if len(describe.LaunchConfigurations) != 0 &&
|
2015-02-20 23:26:43 +01:00
|
|
|
*describe.LaunchConfigurations[0].LaunchConfigurationName == rs.Primary.ID {
|
2014-07-14 20:10:13 +02:00
|
|
|
return fmt.Errorf("Launch Configuration still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the error
|
2015-05-20 13:21:23 +02:00
|
|
|
providerErr, ok := err.(awserr.Error)
|
2014-07-14 20:10:13 +02:00
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-20 13:21:23 +02:00
|
|
|
if providerErr.Code() != "InvalidLaunchConfiguration.NotFound" {
|
2014-07-14 20:10:13 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSLaunchConfigurationAttributes(conf *autoscaling.LaunchConfiguration) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
2015-08-17 20:27:16 +02:00
|
|
|
if *conf.ImageId != "ami-21f78e11" {
|
|
|
|
return fmt.Errorf("Bad image_id: %s", *conf.ImageId)
|
2014-07-14 20:10:13 +02:00
|
|
|
}
|
|
|
|
|
2015-04-02 17:47:37 +02:00
|
|
|
if !strings.HasPrefix(*conf.LaunchConfigurationName, "terraform-") {
|
2015-02-20 23:26:43 +01:00
|
|
|
return fmt.Errorf("Bad name: %s", *conf.LaunchConfigurationName)
|
2014-07-14 20:10:13 +02:00
|
|
|
}
|
|
|
|
|
2015-04-02 17:47:37 +02:00
|
|
|
if *conf.InstanceType != "m1.small" {
|
2015-02-20 23:26:43 +01:00
|
|
|
return fmt.Errorf("Bad instance_type: %s", *conf.InstanceType)
|
2014-07-14 20:10:13 +02:00
|
|
|
}
|
|
|
|
|
2015-04-02 17:47:37 +02:00
|
|
|
// Map out the block devices by name, which should be unique.
|
2015-04-16 14:10:17 +02:00
|
|
|
blockDevices := make(map[string]*autoscaling.BlockDeviceMapping)
|
2015-04-02 17:47:37 +02:00
|
|
|
for _, blockDevice := range conf.BlockDeviceMappings {
|
|
|
|
blockDevices[*blockDevice.DeviceName] = blockDevice
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the root block device exists.
|
|
|
|
if _, ok := blockDevices["/dev/sda1"]; !ok {
|
2015-12-01 16:31:20 +01:00
|
|
|
return fmt.Errorf("block device doesn't exist: /dev/sda1")
|
2015-04-02 17:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the secondary block device exists.
|
|
|
|
if _, ok := blockDevices["/dev/sdb"]; !ok {
|
2015-12-01 16:31:20 +01:00
|
|
|
return fmt.Errorf("block device doesn't exist: /dev/sdb")
|
2015-04-02 17:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the third block device exists.
|
|
|
|
if _, ok := blockDevices["/dev/sdc"]; !ok {
|
2015-12-01 16:31:20 +01:00
|
|
|
return fmt.Errorf("block device doesn't exist: /dev/sdc")
|
2015-04-02 17:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the secondary block device exists.
|
|
|
|
if _, ok := blockDevices["/dev/sdb"]; !ok {
|
|
|
|
return fmt.Errorf("block device doesn't exist: /dev/sdb")
|
|
|
|
}
|
|
|
|
|
2014-07-14 20:10:13 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSLaunchConfigurationExists(n string, res *autoscaling.LaunchConfiguration) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
2014-09-17 02:44:42 +02:00
|
|
|
rs, ok := s.RootModule().Resources[n]
|
2014-07-14 20:10:13 +02:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
if rs.Primary.ID == "" {
|
2014-07-14 20:10:13 +02:00
|
|
|
return fmt.Errorf("No Launch Configuration ID is set")
|
|
|
|
}
|
|
|
|
|
2014-11-21 17:58:34 +01:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
|
2014-07-14 20:10:13 +02:00
|
|
|
|
2015-04-16 14:10:17 +02:00
|
|
|
describeOpts := autoscaling.DescribeLaunchConfigurationsInput{
|
|
|
|
LaunchConfigurationNames: []*string{aws.String(rs.Primary.ID)},
|
2014-07-14 20:10:13 +02:00
|
|
|
}
|
|
|
|
describe, err := conn.DescribeLaunchConfigurations(&describeOpts)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(describe.LaunchConfigurations) != 1 ||
|
2015-02-20 23:26:43 +01:00
|
|
|
*describe.LaunchConfigurations[0].LaunchConfigurationName != rs.Primary.ID {
|
2014-07-14 20:10:13 +02:00
|
|
|
return fmt.Errorf("Launch Configuration Group not found")
|
|
|
|
}
|
|
|
|
|
2015-04-16 14:10:17 +02:00
|
|
|
*res = *describe.LaunchConfigurations[0]
|
2014-07-14 20:10:13 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 17:47:37 +02:00
|
|
|
var testAccAWSLaunchConfigurationConfig = fmt.Sprintf(`
|
2014-07-14 20:10:13 +02:00
|
|
|
resource "aws_launch_configuration" "bar" {
|
2015-04-02 17:47:37 +02:00
|
|
|
name = "terraform-test-%d"
|
2014-10-10 23:50:23 +02:00
|
|
|
image_id = "ami-21f78e11"
|
2015-04-02 17:47:37 +02:00
|
|
|
instance_type = "m1.small"
|
2014-07-29 23:30:24 +02:00
|
|
|
user_data = "foobar-user-data"
|
2014-11-24 05:26:03 +01:00
|
|
|
associate_public_ip_address = true
|
2015-04-02 17:47:37 +02:00
|
|
|
|
|
|
|
root_block_device {
|
|
|
|
volume_type = "gp2"
|
|
|
|
volume_size = 11
|
|
|
|
}
|
|
|
|
ebs_block_device {
|
|
|
|
device_name = "/dev/sdb"
|
|
|
|
volume_size = 9
|
|
|
|
}
|
|
|
|
ebs_block_device {
|
|
|
|
device_name = "/dev/sdc"
|
|
|
|
volume_size = 10
|
|
|
|
volume_type = "io1"
|
|
|
|
iops = 100
|
|
|
|
}
|
|
|
|
ephemeral_block_device {
|
|
|
|
device_name = "/dev/sde"
|
|
|
|
virtual_name = "ephemeral0"
|
|
|
|
}
|
2014-07-14 20:10:13 +02:00
|
|
|
}
|
2015-04-02 17:47:37 +02:00
|
|
|
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
|
2015-01-23 22:51:25 +01:00
|
|
|
|
2015-04-02 17:47:37 +02:00
|
|
|
var testAccAWSLaunchConfigurationWithSpotPriceConfig = fmt.Sprintf(`
|
2015-01-23 22:51:25 +01:00
|
|
|
resource "aws_launch_configuration" "bar" {
|
2015-04-02 17:47:37 +02:00
|
|
|
name = "terraform-test-%d"
|
2015-01-23 22:51:25 +01:00
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
spot_price = "0.01"
|
|
|
|
}
|
2015-04-02 17:47:37 +02:00
|
|
|
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
|
2015-02-27 19:15:12 +01:00
|
|
|
|
|
|
|
const testAccAWSLaunchConfigurationNoNameConfig = `
|
|
|
|
resource "aws_launch_configuration" "bar" {
|
2015-04-02 17:47:37 +02:00
|
|
|
image_id = "ami-21f78e11"
|
2015-02-27 19:15:12 +01:00
|
|
|
instance_type = "t1.micro"
|
|
|
|
user_data = "foobar-user-data-change"
|
|
|
|
associate_public_ip_address = false
|
|
|
|
}
|
|
|
|
`
|
2015-11-07 08:25:07 +01:00
|
|
|
|
|
|
|
const testAccAWSLaunchConfigurationPrefixNameConfig = `
|
|
|
|
resource "aws_launch_configuration" "baz" {
|
|
|
|
name_prefix = "baz-"
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
user_data = "foobar-user-data-change"
|
|
|
|
associate_public_ip_address = false
|
|
|
|
}
|
|
|
|
`
|
2016-01-06 08:36:39 +01:00
|
|
|
|
|
|
|
const testAccAWSLaunchConfigurationWithEncryption = `
|
|
|
|
resource "aws_launch_configuration" "baz" {
|
|
|
|
image_id = "ami-5189a661"
|
|
|
|
instance_type = "t2.micro"
|
|
|
|
associate_public_ip_address = false
|
|
|
|
|
|
|
|
root_block_device {
|
|
|
|
volume_type = "gp2"
|
|
|
|
volume_size = 11
|
|
|
|
}
|
|
|
|
ebs_block_device {
|
|
|
|
device_name = "/dev/sdb"
|
|
|
|
volume_size = 9
|
|
|
|
encrypted = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2016-07-16 16:13:29 +02:00
|
|
|
const testAccAWSLaunchConfigurationConfig_withVpcClassicLink = `
|
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
enable_classiclink = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "foo" {
|
|
|
|
name = "foo"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_launch_configuration" "foo" {
|
|
|
|
name = "TestAccAWSLaunchConfiguration_withVpcClassicLink"
|
2016-07-16 16:17:37 +02:00
|
|
|
image_id = "ami-21f78e11"
|
2016-07-16 16:13:29 +02:00
|
|
|
instance_type = "t1.micro"
|
|
|
|
|
|
|
|
vpc_classic_link_id = "${aws_vpc.foo.id}"
|
|
|
|
vpc_classic_link_security_groups = ["${aws_security_group.foo.id}"]
|
|
|
|
}
|
|
|
|
`
|
2016-03-25 19:07:47 +01:00
|
|
|
|
|
|
|
const testAccAWSLaunchConfigurationConfig_withIAMProfile = `
|
|
|
|
resource "aws_iam_role" "role" {
|
|
|
|
name = "TestAccAWSLaunchConfiguration-withIAMProfile"
|
|
|
|
assume_role_policy = <<EOF
|
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Action": "sts:AssumeRole",
|
|
|
|
"Principal": {
|
|
|
|
"Service": "ec2.amazonaws.com"
|
|
|
|
},
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Sid": ""
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_iam_instance_profile" "profile" {
|
|
|
|
name = "TestAccAWSLaunchConfiguration-withIAMProfile"
|
|
|
|
roles = ["${aws_iam_role.role.name}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_launch_configuration" "bar" {
|
|
|
|
image_id = "ami-5189a661"
|
|
|
|
instance_type = "t2.nano"
|
|
|
|
iam_instance_profile = "${aws_iam_instance_profile.profile.name}"
|
|
|
|
}
|
|
|
|
`
|