provider/aws/spot_fleet_request: fixed reading network associate_public_ip_address configuration (#13748)

This commit is contained in:
Jan Škrášek 2017-06-07 22:14:00 +02:00 committed by Clint
parent 3bfc46137a
commit 70e8d2d33f
2 changed files with 103 additions and 1 deletions

View File

@ -801,7 +801,9 @@ func launchSpecToMap(l *ec2.SpotFleetLaunchSpecification, rootDevName *string) m
securityGroupIds := &schema.Set{F: schema.HashString} securityGroupIds := &schema.Set{F: schema.HashString}
if len(l.NetworkInterfaces) > 0 { if len(l.NetworkInterfaces) > 0 {
// This resource auto-creates one network interface when associate_public_ip_address is true m["associate_public_ip_address"] = aws.BoolValue(l.NetworkInterfaces[0].AssociatePublicIpAddress)
m["subnet_id"] = aws.StringValue(l.NetworkInterfaces[0].SubnetId)
for _, group := range l.NetworkInterfaces[0].Groups { for _, group := range l.NetworkInterfaces[0].Groups {
securityGroupIds.Add(aws.StringValue(group)) securityGroupIds.Add(aws.StringValue(group))
} }

View File

@ -14,6 +14,33 @@ import (
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccAWSSpotFleetRequest_associatePublicIpAddress(t *testing.T) {
var sfr ec2.SpotFleetRequestConfig
rName := acctest.RandString(10)
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSpotFleetRequestConfigAssociatePublicIpAddress(rName, rInt),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSSpotFleetRequestExists(
"aws_spot_fleet_request.foo", &sfr),
resource.TestCheckResourceAttr(
"aws_spot_fleet_request.foo", "spot_request_state", "active"),
resource.TestCheckResourceAttr(
"aws_spot_fleet_request.foo", "launch_specification.#", "1"),
resource.TestCheckResourceAttr(
"aws_spot_fleet_request.foo", "launch_specification.2633484960.associate_public_ip_address", "true"),
),
},
},
})
}
func TestAccAWSSpotFleetRequest_changePriceForcesNewRequest(t *testing.T) { func TestAccAWSSpotFleetRequest_changePriceForcesNewRequest(t *testing.T) {
var before, after ec2.SpotFleetRequestConfig var before, after ec2.SpotFleetRequestConfig
rName := acctest.RandString(10) rName := acctest.RandString(10)
@ -466,6 +493,79 @@ func testAccCheckAWSSpotFleetRequestDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccAWSSpotFleetRequestConfigAssociatePublicIpAddress(rName string, rInt int) string {
return fmt.Sprintf(`
resource "aws_key_pair" "debugging" {
key_name = "tmp-key-%s"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
}
resource "aws_iam_policy" "test-policy" {
name = "test-policy-%d"
path = "/"
description = "Spot Fleet Request ACCTest Policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"ec2:DescribeImages",
"ec2:DescribeSubnets",
"ec2:RequestSpotInstances",
"ec2:TerminateInstances",
"ec2:DescribeInstanceStatus",
"iam:PassRole"
],
"Resource": ["*"]
}]
}
EOF
}
resource "aws_iam_policy_attachment" "test-attach" {
name = "test-attachment-%d"
roles = ["${aws_iam_role.test-role.name}"]
policy_arn = "${aws_iam_policy.test-policy.arn}"
}
resource "aws_iam_role" "test-role" {
name = "test-role-%s"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": [
"spotfleet.amazonaws.com",
"ec2.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_spot_fleet_request" "foo" {
iam_fleet_role = "${aws_iam_role.test-role.arn}"
spot_price = "0.005"
target_capacity = 2
valid_until = "2019-11-04T20:44:20Z"
terminate_instances_with_expiration = true
launch_specification {
instance_type = "m1.small"
ami = "ami-d06a90b0"
key_name = "${aws_key_pair.debugging.key_name}"
associate_public_ip_address = true
}
}`, rName, rInt, rInt, rName)
}
func testAccAWSSpotFleetRequestConfig(rName string, rInt int) string { func testAccAWSSpotFleetRequestConfig(rName string, rInt int) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "aws_key_pair" "debugging" { resource "aws_key_pair" "debugging" {