providers/aws: aws_instance id-only
This commit is contained in:
parent
46430cd384
commit
d85df63526
|
@ -533,6 +533,9 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
if err := d.Set("vpc_security_group_ids", sgs); err != nil {
|
if err := d.Set("vpc_security_group_ids", sgs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := d.Set("security_groups", []string{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, sg := range instance.SecurityGroups {
|
for _, sg := range instance.SecurityGroups {
|
||||||
sgs = append(sgs, *sg.GroupName)
|
sgs = append(sgs, *sg.GroupName)
|
||||||
|
@ -541,11 +544,29 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
if err := d.Set("security_groups", sgs); err != nil {
|
if err := d.Set("security_groups", sgs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := d.Set("vpc_security_group_ids", []string{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := readBlockDevices(d, instance, conn); err != nil {
|
if err := readBlockDevices(d, instance, conn); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if _, ok := d.GetOk("ephemeral_block_device"); !ok {
|
||||||
|
d.Set("ephemeral_block_device", []interface{}{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instance attributes
|
||||||
|
{
|
||||||
|
attr, err := conn.DescribeInstanceAttribute(&ec2.DescribeInstanceAttributeInput{
|
||||||
|
Attribute: aws.String("disableApiTermination"),
|
||||||
|
InstanceId: aws.String(d.Id()),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.Set("disable_api_termination", attr.DisableApiTermination.Value)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -696,8 +717,17 @@ func readBlockDevices(d *schema.ResourceData, instance *ec2.Instance, conn *ec2.
|
||||||
if err := d.Set("ebs_block_device", ibds["ebs"]); err != nil {
|
if err := d.Set("ebs_block_device", ibds["ebs"]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This handles the import case which needs to be defaulted to empty
|
||||||
|
if _, ok := d.GetOk("root_block_device"); !ok {
|
||||||
|
if err := d.Set("root_block_device", []interface{}{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ibds["root"] != nil {
|
if ibds["root"] != nil {
|
||||||
if err := d.Set("root_block_device", []interface{}{ibds["root"]}); err != nil {
|
roots := []interface{}{ibds["root"]}
|
||||||
|
if err := d.Set("root_block_device", roots); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,13 @@ func TestAccAWSInstance_basic(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
|
||||||
|
// We ignore security groups because even with EC2 classic
|
||||||
|
// we'll import as VPC security groups, which is fine. We verify
|
||||||
|
// VPC security group import in other tests
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
|
IDRefreshIgnore: []string{"user_data", "security_groups", "vpc_security_group_ids"},
|
||||||
|
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -136,6 +143,9 @@ func TestAccAWSInstance_blockDevices(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
|
IDRefreshIgnore: []string{
|
||||||
|
"ephemeral_block_device", "user_data", "security_groups", "vpc_security_groups"},
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -203,6 +213,7 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -256,6 +267,7 @@ func TestAccAWSInstance_disableApiTermination(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -283,6 +295,8 @@ func TestAccAWSInstance_vpc(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
|
IDRefreshIgnore: []string{"associate_public_ip_address", "user_data"},
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -338,6 +352,8 @@ func TestAccAWSInstance_NetworkInstanceSecurityGroups(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo_instance",
|
||||||
|
IDRefreshIgnore: []string{"associate_public_ip_address"},
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -357,6 +373,7 @@ func TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo_instance",
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -420,6 +437,7 @@ func TestAccAWSInstance_privateIP(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -449,6 +467,8 @@ func TestAccAWSInstance_associatePublicIPAndPrivateIP(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
|
IDRefreshIgnore: []string{"associate_public_ip_address"},
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -483,6 +503,8 @@ func TestAccAWSInstance_keyPairCheck(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
|
IDRefreshIgnore: []string{"source_dest_check"},
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
@ -531,6 +553,7 @@ func TestAccAWSInstance_forceNewAndTagsDrift(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
IDRefreshName: "aws_instance.foo",
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckInstanceDestroy,
|
CheckDestroy: testAccCheckInstanceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
|
|
|
@ -317,8 +317,16 @@ func testIDOnlyRefresh(c TestCase, opts terraform.ContextOpts, step TestStep, r
|
||||||
expected := r.Primary.Attributes
|
expected := r.Primary.Attributes
|
||||||
// Remove fields we're ignoring
|
// Remove fields we're ignoring
|
||||||
for _, v := range c.IDRefreshIgnore {
|
for _, v := range c.IDRefreshIgnore {
|
||||||
delete(actual, v)
|
for k, _ := range actual {
|
||||||
delete(expected, v)
|
if strings.HasPrefix(k, v) {
|
||||||
|
delete(actual, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, _ := range expected {
|
||||||
|
if strings.HasPrefix(k, v) {
|
||||||
|
delete(expected, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
|
Loading…
Reference in New Issue