provider/aws: Allow VPC Classic Linking in Autoscaling Launch Configs (#7470)
* support for vpc linking ec2 instances in launch configs * add acceptance testing * generate vpc and security groups for each test run
This commit is contained in:
parent
03157610d8
commit
e85297f958
|
@ -110,6 +110,20 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
|
|||
Set: schema.HashString,
|
||||
},
|
||||
|
||||
"vpc_classic_link_id": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"vpc_classic_link_security_groups": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
Set: schema.HashString,
|
||||
},
|
||||
|
||||
"associate_public_ip_address": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
|
@ -329,6 +343,16 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
|||
)
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("vpc_classic_link_id"); ok {
|
||||
createLaunchConfigurationOpts.ClassicLinkVPCId = aws.String(v.(string))
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("vpc_classic_link_security_groups"); ok {
|
||||
createLaunchConfigurationOpts.ClassicLinkVPCSecurityGroups = expandStringList(
|
||||
v.(*schema.Set).List(),
|
||||
)
|
||||
}
|
||||
|
||||
var blockDevices []*autoscaling.BlockDeviceMapping
|
||||
|
||||
// We'll use this to detect if we're declaring it incorrectly as an ebs_block_device.
|
||||
|
@ -519,6 +543,9 @@ func resourceAwsLaunchConfigurationRead(d *schema.ResourceData, meta interface{}
|
|||
d.Set("enable_monitoring", lc.InstanceMonitoring.Enabled)
|
||||
d.Set("security_groups", lc.SecurityGroups)
|
||||
|
||||
d.Set("vpc_classic_link_id", lc.ClassicLinkVPCId)
|
||||
d.Set("vpc_classic_link_security_groups", lc.ClassicLinkVPCSecurityGroups)
|
||||
|
||||
if err := readLCBlockDevices(d, lc, ec2conn); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/autoscaling"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -89,6 +90,28 @@ func TestAccAWSLaunchConfiguration_withSpotPrice(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
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),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSLaunchConfiguration_withIAMProfile(t *testing.T) {
|
||||
var conf autoscaling.LaunchConfiguration
|
||||
|
||||
|
@ -355,6 +378,26 @@ resource "aws_launch_configuration" "baz" {
|
|||
}
|
||||
}
|
||||
`
|
||||
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"
|
||||
image_id = "ami-2d39803a"
|
||||
instance_type = "t1.micro"
|
||||
|
||||
vpc_classic_link_id = "${aws_vpc.foo.id}"
|
||||
vpc_classic_link_security_groups = ["${aws_security_group.foo.id}"]
|
||||
}
|
||||
`
|
||||
|
||||
const testAccAWSLaunchConfigurationConfig_withIAMProfile = `
|
||||
resource "aws_iam_role" "role" {
|
||||
|
|
|
@ -134,6 +134,8 @@ The following arguments are supported:
|
|||
* `key_name` - (Optional) The key name that should be used for the instance.
|
||||
* `security_groups` - (Optional) A list of associated security group IDS.
|
||||
* `associate_public_ip_address` - (Optional) Associate a public ip address with an instance in a VPC.
|
||||
* `vpc_classic_link_id` - (Optional) The ID of a ClassicLink-enabled VPC. Only applies to EC2-Classic instances. (eg. `vpc-2730681a`)
|
||||
* `vpc_classic_link_security_groups` - (Optional) The IDs of one or more security groups for the specified ClassicLink-enabled VPC (eg. `sg-46ae3d11`).
|
||||
* `user_data` - (Optional) The user data to provide when launching the instance.
|
||||
* `enable_monitoring` - (Optional) Enables/disables detailed monitoring. This is enabled by default.
|
||||
* `ebs_optimized` - (Optional) If true, the launched EC2 instance will be EBS-optimized.
|
||||
|
|
Loading…
Reference in New Issue