github.com/dougneal/terraform@v0.6.15-0.20170330092735-b6a3840768a4/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go (about)

     1  package openstack
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/resource"
     8  	"github.com/hashicorp/terraform/terraform"
     9  
    10  	"github.com/gophercloud/gophercloud"
    11  	"github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes"
    12  	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
    13  	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups"
    14  	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach"
    15  	"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
    16  	"github.com/gophercloud/gophercloud/pagination"
    17  )
    18  
    19  func TestAccComputeV2Instance_basic(t *testing.T) {
    20  	var instance servers.Server
    21  
    22  	resource.Test(t, resource.TestCase{
    23  		PreCheck:     func() { testAccPreCheck(t) },
    24  		Providers:    testAccProviders,
    25  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
    26  		Steps: []resource.TestStep{
    27  			resource.TestStep{
    28  				Config: testAccComputeV2Instance_basic,
    29  				Check: resource.ComposeTestCheckFunc(
    30  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
    31  					testAccCheckComputeV2InstanceMetadata(&instance, "foo", "bar"),
    32  					resource.TestCheckResourceAttr(
    33  						"openstack_compute_instance_v2.instance_1", "all_metadata.foo", "bar"),
    34  					resource.TestCheckResourceAttr(
    35  						"openstack_compute_instance_v2.instance_1", "availability_zone", "nova"),
    36  				),
    37  			},
    38  		},
    39  	})
    40  }
    41  
    42  func TestAccComputeV2Instance_volumeAttach(t *testing.T) {
    43  	var instance servers.Server
    44  	var volume volumes.Volume
    45  
    46  	resource.Test(t, resource.TestCase{
    47  		PreCheck:     func() { testAccPreCheck(t) },
    48  		Providers:    testAccProviders,
    49  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
    50  		Steps: []resource.TestStep{
    51  			resource.TestStep{
    52  				Config: testAccComputeV2Instance_volumeAttach,
    53  				Check: resource.ComposeTestCheckFunc(
    54  					testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.vol_1", &volume),
    55  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
    56  					testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume),
    57  				),
    58  			},
    59  		},
    60  	})
    61  }
    62  
    63  func TestAccComputeV2Instance_volumeAttachPostCreation(t *testing.T) {
    64  	var instance servers.Server
    65  	var volume volumes.Volume
    66  
    67  	resource.Test(t, resource.TestCase{
    68  		PreCheck:     func() { testAccPreCheck(t) },
    69  		Providers:    testAccProviders,
    70  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
    71  		Steps: []resource.TestStep{
    72  			resource.TestStep{
    73  				Config: testAccComputeV2Instance_volumeAttachPostCreation_1,
    74  				Check: resource.ComposeTestCheckFunc(
    75  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
    76  				),
    77  			},
    78  			resource.TestStep{
    79  				Config: testAccComputeV2Instance_volumeAttachPostCreation_2,
    80  				Check: resource.ComposeTestCheckFunc(
    81  					testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.vol_1", &volume),
    82  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
    83  					testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume),
    84  				),
    85  			},
    86  		},
    87  	})
    88  }
    89  
    90  func TestAccComputeV2Instance_volumeDetachPostCreation(t *testing.T) {
    91  	var instance servers.Server
    92  	var volume volumes.Volume
    93  
    94  	resource.Test(t, resource.TestCase{
    95  		PreCheck:     func() { testAccPreCheck(t) },
    96  		Providers:    testAccProviders,
    97  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
    98  		Steps: []resource.TestStep{
    99  			resource.TestStep{
   100  				Config: testAccComputeV2Instance_volumeDetachPostCreation_1,
   101  				Check: resource.ComposeTestCheckFunc(
   102  					testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.vol_1", &volume),
   103  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   104  					testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume),
   105  				),
   106  			},
   107  			resource.TestStep{
   108  				Config: testAccComputeV2Instance_volumeDetachPostCreation_2,
   109  				Check: resource.ComposeTestCheckFunc(
   110  					testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.vol_1", &volume),
   111  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   112  					testAccCheckComputeV2InstanceVolumesDetached(&instance),
   113  				),
   114  			},
   115  		},
   116  	})
   117  }
   118  
   119  func TestAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation(t *testing.T) {
   120  	var instance servers.Server
   121  	var volume_1 volumes.Volume
   122  	var volume_2 volumes.Volume
   123  
   124  	resource.Test(t, resource.TestCase{
   125  		PreCheck:     func() { testAccPreCheck(t) },
   126  		Providers:    testAccProviders,
   127  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   128  		Steps: []resource.TestStep{
   129  			resource.TestStep{
   130  				Config: testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_1,
   131  				Check: resource.ComposeTestCheckFunc(
   132  					testAccCheckBlockStorageV1VolumeExists(
   133  						"openstack_blockstorage_volume_v1.root_volume", &volume_1),
   134  					testAccCheckBlockStorageV1VolumeExists(
   135  						"openstack_blockstorage_volume_v1.additional_volume", &volume_2),
   136  					testAccCheckComputeV2InstanceExists(
   137  						"openstack_compute_instance_v2.instance_1", &instance),
   138  					testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_1),
   139  					testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_2),
   140  				),
   141  			},
   142  			resource.TestStep{
   143  				Config: testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_2,
   144  				Check: resource.ComposeTestCheckFunc(
   145  					testAccCheckBlockStorageV1VolumeExists(
   146  						"openstack_blockstorage_volume_v1.root_volume", &volume_1),
   147  					testAccCheckBlockStorageV1VolumeExists(
   148  						"openstack_blockstorage_volume_v1.additional_volume", &volume_2),
   149  					testAccCheckComputeV2InstanceExists(
   150  						"openstack_compute_instance_v2.instance_1", &instance),
   151  					testAccCheckComputeV2InstanceVolumeDetached(
   152  						&instance, "openstack_blockstorage_volume_v1.additional_volume"),
   153  					testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_1),
   154  				),
   155  			},
   156  		},
   157  	})
   158  }
   159  
   160  func TestAccComputeV2Instance_volumeAttachInstanceDelete(t *testing.T) {
   161  	var instance servers.Server
   162  	var volume_1 volumes.Volume
   163  	var volume_2 volumes.Volume
   164  
   165  	resource.Test(t, resource.TestCase{
   166  		PreCheck:     func() { testAccPreCheck(t) },
   167  		Providers:    testAccProviders,
   168  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   169  		Steps: []resource.TestStep{
   170  			resource.TestStep{
   171  				Config: testAccComputeV2Instance_volumeAttachInstanceDelete_1,
   172  				Check: resource.ComposeTestCheckFunc(
   173  					testAccCheckBlockStorageV1VolumeExists(
   174  						"openstack_blockstorage_volume_v1.root_volume", &volume_1),
   175  					testAccCheckBlockStorageV1VolumeExists(
   176  						"openstack_blockstorage_volume_v1.additional_volume", &volume_2),
   177  					testAccCheckComputeV2InstanceExists(
   178  						"openstack_compute_instance_v2.instance_1", &instance),
   179  					testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_1),
   180  					testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_2),
   181  				),
   182  			},
   183  			resource.TestStep{
   184  				Config: testAccComputeV2Instance_volumeAttachInstanceDelete_2,
   185  				Check: resource.ComposeTestCheckFunc(
   186  					testAccCheckBlockStorageV1VolumeExists(
   187  						"openstack_blockstorage_volume_v1.root_volume", &volume_1),
   188  					testAccCheckBlockStorageV1VolumeExists(
   189  						"openstack_blockstorage_volume_v1.additional_volume", &volume_2),
   190  					testAccCheckComputeV2InstanceDoesNotExist(
   191  						"openstack_compute_instance_v2.instance_1", &instance),
   192  					testAccCheckComputeV2InstanceVolumeDetached(
   193  						&instance, "openstack_blockstorage_volume_v1.root_volume"),
   194  					testAccCheckComputeV2InstanceVolumeDetached(
   195  						&instance, "openstack_blockstorage_volume_v1.additional_volume"),
   196  				),
   197  			},
   198  		},
   199  	})
   200  }
   201  
   202  func TestAccComputeV2Instance_volumeAttachToNewInstance(t *testing.T) {
   203  	var instance_1 servers.Server
   204  	var instance_2 servers.Server
   205  	var volume_1 volumes.Volume
   206  
   207  	resource.Test(t, resource.TestCase{
   208  		PreCheck:     func() { testAccPreCheck(t) },
   209  		Providers:    testAccProviders,
   210  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   211  		Steps: []resource.TestStep{
   212  			resource.TestStep{
   213  				Config: testAccComputeV2Instance_volumeAttachToNewInstance_1,
   214  				Check: resource.ComposeTestCheckFunc(
   215  					testAccCheckBlockStorageV1VolumeExists(
   216  						"openstack_blockstorage_volume_v1.volume_1", &volume_1),
   217  					testAccCheckComputeV2InstanceExists(
   218  						"openstack_compute_instance_v2.instance_1", &instance_1),
   219  					testAccCheckComputeV2InstanceExists(
   220  						"openstack_compute_instance_v2.instance_2", &instance_2),
   221  					testAccCheckComputeV2InstanceVolumeDetached(
   222  						&instance_2, "openstack_blockstorage_volume_v1.volume_1"),
   223  					testAccCheckComputeV2InstanceVolumeAttachment(&instance_1, &volume_1),
   224  				),
   225  			},
   226  			resource.TestStep{
   227  				Config: testAccComputeV2Instance_volumeAttachToNewInstance_2,
   228  				Check: resource.ComposeTestCheckFunc(
   229  					testAccCheckBlockStorageV1VolumeExists(
   230  						"openstack_blockstorage_volume_v1.volume_1", &volume_1),
   231  					testAccCheckComputeV2InstanceExists(
   232  						"openstack_compute_instance_v2.instance_1", &instance_1),
   233  					testAccCheckComputeV2InstanceExists(
   234  						"openstack_compute_instance_v2.instance_2", &instance_2),
   235  					testAccCheckComputeV2InstanceVolumeDetached(
   236  						&instance_1, "openstack_blockstorage_volume_v1.volume_1"),
   237  					testAccCheckComputeV2InstanceVolumeAttachment(&instance_2, &volume_1),
   238  				),
   239  			},
   240  		},
   241  	})
   242  }
   243  
   244  func TestAccComputeV2Instance_floatingIPAttachGlobally(t *testing.T) {
   245  	var instance servers.Server
   246  	var fip floatingips.FloatingIP
   247  
   248  	resource.Test(t, resource.TestCase{
   249  		PreCheck:     func() { testAccPreCheck(t) },
   250  		Providers:    testAccProviders,
   251  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   252  		Steps: []resource.TestStep{
   253  			resource.TestStep{
   254  				Config: testAccComputeV2Instance_floatingIPAttachGlobally,
   255  				Check: resource.ComposeTestCheckFunc(
   256  					testAccCheckComputeV2FloatingIPExists("openstack_compute_floatingip_v2.fip_1", &fip),
   257  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   258  					testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip),
   259  				),
   260  			},
   261  		},
   262  	})
   263  }
   264  
   265  func TestAccComputeV2Instance_floatingIPAttachToNetwork(t *testing.T) {
   266  	var instance servers.Server
   267  	var fip floatingips.FloatingIP
   268  
   269  	resource.Test(t, resource.TestCase{
   270  		PreCheck:     func() { testAccPreCheck(t) },
   271  		Providers:    testAccProviders,
   272  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   273  		Steps: []resource.TestStep{
   274  			resource.TestStep{
   275  				Config: testAccComputeV2Instance_floatingIPAttachToNetwork,
   276  				Check: resource.ComposeTestCheckFunc(
   277  					testAccCheckComputeV2FloatingIPExists("openstack_compute_floatingip_v2.fip_1", &fip),
   278  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   279  					testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip),
   280  				),
   281  			},
   282  		},
   283  	})
   284  }
   285  
   286  func TestAccComputeV2Instance_floatingIPAttachToNetworkAndChange(t *testing.T) {
   287  	var instance servers.Server
   288  	var fip floatingips.FloatingIP
   289  
   290  	resource.Test(t, resource.TestCase{
   291  		PreCheck:     func() { testAccPreCheck(t) },
   292  		Providers:    testAccProviders,
   293  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   294  		Steps: []resource.TestStep{
   295  			resource.TestStep{
   296  				Config: testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_1,
   297  				Check: resource.ComposeTestCheckFunc(
   298  					testAccCheckComputeV2FloatingIPExists("openstack_compute_floatingip_v2.fip_1", &fip),
   299  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   300  					testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip),
   301  				),
   302  			},
   303  			resource.TestStep{
   304  				Config: testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_2,
   305  				Check: resource.ComposeTestCheckFunc(
   306  					testAccCheckComputeV2FloatingIPExists("openstack_compute_floatingip_v2.fip_2", &fip),
   307  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   308  					testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip),
   309  				),
   310  			},
   311  		},
   312  	})
   313  }
   314  
   315  func TestAccComputeV2Instance_secgroupMulti(t *testing.T) {
   316  	var instance_1 servers.Server
   317  	var secgroup_1 secgroups.SecurityGroup
   318  
   319  	resource.Test(t, resource.TestCase{
   320  		PreCheck:     func() { testAccPreCheck(t) },
   321  		Providers:    testAccProviders,
   322  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   323  		Steps: []resource.TestStep{
   324  			resource.TestStep{
   325  				Config: testAccComputeV2Instance_secgroupMulti,
   326  				Check: resource.ComposeTestCheckFunc(
   327  					testAccCheckComputeV2SecGroupExists(
   328  						"openstack_compute_secgroup_v2.secgroup_1", &secgroup_1),
   329  					testAccCheckComputeV2InstanceExists(
   330  						"openstack_compute_instance_v2.instance_1", &instance_1),
   331  				),
   332  			},
   333  		},
   334  	})
   335  }
   336  
   337  func TestAccComputeV2Instance_secgroupMultiUpdate(t *testing.T) {
   338  	var instance_1 servers.Server
   339  	var secgroup_1, secgroup_2 secgroups.SecurityGroup
   340  
   341  	resource.Test(t, resource.TestCase{
   342  		PreCheck:     func() { testAccPreCheck(t) },
   343  		Providers:    testAccProviders,
   344  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   345  		Steps: []resource.TestStep{
   346  			resource.TestStep{
   347  				Config: testAccComputeV2Instance_secgroupMultiUpdate_1,
   348  				Check: resource.ComposeTestCheckFunc(
   349  					testAccCheckComputeV2SecGroupExists(
   350  						"openstack_compute_secgroup_v2.secgroup_1", &secgroup_1),
   351  					testAccCheckComputeV2SecGroupExists(
   352  						"openstack_compute_secgroup_v2.secgroup_2", &secgroup_2),
   353  					testAccCheckComputeV2InstanceExists(
   354  						"openstack_compute_instance_v2.instance_1", &instance_1),
   355  				),
   356  			},
   357  			resource.TestStep{
   358  				Config: testAccComputeV2Instance_secgroupMultiUpdate_2,
   359  				Check: resource.ComposeTestCheckFunc(
   360  					testAccCheckComputeV2SecGroupExists(
   361  						"openstack_compute_secgroup_v2.secgroup_1", &secgroup_1),
   362  					testAccCheckComputeV2SecGroupExists(
   363  						"openstack_compute_secgroup_v2.secgroup_2", &secgroup_2),
   364  					testAccCheckComputeV2InstanceExists(
   365  						"openstack_compute_instance_v2.instance_1", &instance_1),
   366  				),
   367  			},
   368  		},
   369  	})
   370  }
   371  
   372  func TestAccComputeV2Instance_bootFromVolumeImage(t *testing.T) {
   373  	var instance servers.Server
   374  
   375  	resource.Test(t, resource.TestCase{
   376  		PreCheck:     func() { testAccPreCheck(t) },
   377  		Providers:    testAccProviders,
   378  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   379  		Steps: []resource.TestStep{
   380  			resource.TestStep{
   381  				Config: testAccComputeV2Instance_bootFromVolumeImage,
   382  				Check: resource.ComposeTestCheckFunc(
   383  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   384  					testAccCheckComputeV2InstanceBootVolumeAttachment(&instance),
   385  				),
   386  			},
   387  		},
   388  	})
   389  }
   390  
   391  func TestAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume(t *testing.T) {
   392  	var instance servers.Server
   393  
   394  	resource.Test(t, resource.TestCase{
   395  		PreCheck:     func() { testAccPreCheck(t) },
   396  		Providers:    testAccProviders,
   397  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   398  		Steps: []resource.TestStep{
   399  			resource.TestStep{
   400  				Config: testAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume,
   401  				Check: resource.ComposeTestCheckFunc(
   402  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   403  				),
   404  			},
   405  		},
   406  	})
   407  }
   408  
   409  func TestAccComputeV2Instance_bootFromVolumeVolume(t *testing.T) {
   410  	var instance servers.Server
   411  
   412  	resource.Test(t, resource.TestCase{
   413  		PreCheck:     func() { testAccPreCheck(t) },
   414  		Providers:    testAccProviders,
   415  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   416  		Steps: []resource.TestStep{
   417  			resource.TestStep{
   418  				Config: testAccComputeV2Instance_bootFromVolumeVolume,
   419  				Check: resource.ComposeTestCheckFunc(
   420  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   421  					testAccCheckComputeV2InstanceBootVolumeAttachment(&instance),
   422  				),
   423  			},
   424  		},
   425  	})
   426  }
   427  
   428  func TestAccComputeV2Instance_bootFromVolumeForceNew(t *testing.T) {
   429  	var instance1_1 servers.Server
   430  	var instance1_2 servers.Server
   431  
   432  	resource.Test(t, resource.TestCase{
   433  		PreCheck:     func() { testAccPreCheck(t) },
   434  		Providers:    testAccProviders,
   435  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   436  		Steps: []resource.TestStep{
   437  			resource.TestStep{
   438  				Config: testAccComputeV2Instance_bootFromVolumeForceNew_1,
   439  				Check: resource.ComposeTestCheckFunc(
   440  					testAccCheckComputeV2InstanceExists(
   441  						"openstack_compute_instance_v2.instance_1", &instance1_1),
   442  				),
   443  			},
   444  			resource.TestStep{
   445  				Config: testAccComputeV2Instance_bootFromVolumeForceNew_2,
   446  				Check: resource.ComposeTestCheckFunc(
   447  					testAccCheckComputeV2InstanceExists(
   448  						"openstack_compute_instance_v2.instance_1", &instance1_2),
   449  					testAccCheckComputeV2InstanceInstanceIDsDoNotMatch(&instance1_1, &instance1_2),
   450  				),
   451  			},
   452  		},
   453  	})
   454  }
   455  
   456  func TestAccComputeV2Instance_blockDeviceNewVolume(t *testing.T) {
   457  	var instance servers.Server
   458  
   459  	resource.Test(t, resource.TestCase{
   460  		PreCheck:     func() { testAccPreCheck(t) },
   461  		Providers:    testAccProviders,
   462  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   463  		Steps: []resource.TestStep{
   464  			resource.TestStep{
   465  				Config: testAccComputeV2Instance_blockDeviceNewVolume,
   466  				Check: resource.ComposeTestCheckFunc(
   467  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   468  				),
   469  			},
   470  		},
   471  	})
   472  }
   473  
   474  func TestAccComputeV2Instance_blockDeviceExistingVolume(t *testing.T) {
   475  	var instance servers.Server
   476  	var volume volumes.Volume
   477  
   478  	resource.Test(t, resource.TestCase{
   479  		PreCheck:     func() { testAccPreCheck(t) },
   480  		Providers:    testAccProviders,
   481  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   482  		Steps: []resource.TestStep{
   483  			resource.TestStep{
   484  				Config: testAccComputeV2Instance_blockDeviceExistingVolume,
   485  				Check: resource.ComposeTestCheckFunc(
   486  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   487  					testAccCheckBlockStorageV1VolumeExists(
   488  						"openstack_blockstorage_volume_v1.volume_1", &volume),
   489  				),
   490  			},
   491  		},
   492  	})
   493  }
   494  
   495  // TODO: verify the personality really exists on the instance.
   496  func TestAccComputeV2Instance_personality(t *testing.T) {
   497  	var instance servers.Server
   498  
   499  	resource.Test(t, resource.TestCase{
   500  		PreCheck:     func() { testAccPreCheck(t) },
   501  		Providers:    testAccProviders,
   502  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   503  		Steps: []resource.TestStep{
   504  			resource.TestStep{
   505  				Config: testAccComputeV2Instance_personality,
   506  				Check: resource.ComposeTestCheckFunc(
   507  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   508  				),
   509  			},
   510  		},
   511  	})
   512  }
   513  
   514  func TestAccComputeV2Instance_multiEphemeral(t *testing.T) {
   515  	var instance servers.Server
   516  
   517  	resource.Test(t, resource.TestCase{
   518  		PreCheck:     func() { testAccPreCheck(t) },
   519  		Providers:    testAccProviders,
   520  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   521  		Steps: []resource.TestStep{
   522  			resource.TestStep{
   523  				Config: testAccComputeV2Instance_multiEphemeral,
   524  				Check: resource.ComposeTestCheckFunc(
   525  					testAccCheckComputeV2InstanceExists(
   526  						"openstack_compute_instance_v2.instance_1", &instance),
   527  				),
   528  			},
   529  		},
   530  	})
   531  }
   532  
   533  func TestAccComputeV2Instance_accessIPv4(t *testing.T) {
   534  	var instance servers.Server
   535  
   536  	resource.Test(t, resource.TestCase{
   537  		PreCheck:     func() { testAccPreCheck(t) },
   538  		Providers:    testAccProviders,
   539  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   540  		Steps: []resource.TestStep{
   541  			resource.TestStep{
   542  				Config: testAccComputeV2Instance_accessIPv4,
   543  				Check: resource.ComposeTestCheckFunc(
   544  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   545  					resource.TestCheckResourceAttr(
   546  						"openstack_compute_instance_v2.instance_1", "access_ip_v4", "192.168.1.100"),
   547  				),
   548  			},
   549  		},
   550  	})
   551  }
   552  
   553  func TestAccComputeV2Instance_changeFixedIP(t *testing.T) {
   554  	var instance1_1 servers.Server
   555  	var instance1_2 servers.Server
   556  
   557  	resource.Test(t, resource.TestCase{
   558  		PreCheck:     func() { testAccPreCheck(t) },
   559  		Providers:    testAccProviders,
   560  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   561  		Steps: []resource.TestStep{
   562  			resource.TestStep{
   563  				Config: testAccComputeV2Instance_changeFixedIP_1,
   564  				Check: resource.ComposeTestCheckFunc(
   565  					testAccCheckComputeV2InstanceExists(
   566  						"openstack_compute_instance_v2.instance_1", &instance1_1),
   567  				),
   568  			},
   569  			resource.TestStep{
   570  				Config: testAccComputeV2Instance_changeFixedIP_2,
   571  				Check: resource.ComposeTestCheckFunc(
   572  					testAccCheckComputeV2InstanceExists(
   573  						"openstack_compute_instance_v2.instance_1", &instance1_2),
   574  					testAccCheckComputeV2InstanceInstanceIDsDoNotMatch(&instance1_1, &instance1_2),
   575  				),
   576  			},
   577  		},
   578  	})
   579  }
   580  
   581  func TestAccComputeV2Instance_stopBeforeDestroy(t *testing.T) {
   582  	var instance servers.Server
   583  	resource.Test(t, resource.TestCase{
   584  		PreCheck:     func() { testAccPreCheck(t) },
   585  		Providers:    testAccProviders,
   586  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   587  		Steps: []resource.TestStep{
   588  			resource.TestStep{
   589  				Config: testAccComputeV2Instance_stopBeforeDestroy,
   590  				Check: resource.ComposeTestCheckFunc(
   591  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   592  				),
   593  			},
   594  		},
   595  	})
   596  }
   597  
   598  func TestAccComputeV2Instance_metadataRemove(t *testing.T) {
   599  	var instance servers.Server
   600  
   601  	resource.Test(t, resource.TestCase{
   602  		PreCheck:     func() { testAccPreCheck(t) },
   603  		Providers:    testAccProviders,
   604  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   605  		Steps: []resource.TestStep{
   606  			resource.TestStep{
   607  				Config: testAccComputeV2Instance_metadataRemove_1,
   608  				Check: resource.ComposeTestCheckFunc(
   609  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   610  					testAccCheckComputeV2InstanceMetadata(&instance, "foo", "bar"),
   611  					testAccCheckComputeV2InstanceMetadata(&instance, "abc", "def"),
   612  					resource.TestCheckResourceAttr(
   613  						"openstack_compute_instance_v2.instance_1", "all_metadata.foo", "bar"),
   614  					resource.TestCheckResourceAttr(
   615  						"openstack_compute_instance_v2.instance_1", "all_metadata.abc", "def"),
   616  				),
   617  			},
   618  			resource.TestStep{
   619  				Config: testAccComputeV2Instance_metadataRemove_2,
   620  				Check: resource.ComposeTestCheckFunc(
   621  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   622  					testAccCheckComputeV2InstanceMetadata(&instance, "foo", "bar"),
   623  					testAccCheckComputeV2InstanceMetadata(&instance, "ghi", "jkl"),
   624  					testAccCheckComputeV2InstanceNoMetadataKey(&instance, "abc"),
   625  					resource.TestCheckResourceAttr(
   626  						"openstack_compute_instance_v2.instance_1", "all_metadata.foo", "bar"),
   627  					resource.TestCheckResourceAttr(
   628  						"openstack_compute_instance_v2.instance_1", "all_metadata.ghi", "jkl"),
   629  				),
   630  			},
   631  		},
   632  	})
   633  }
   634  
   635  func TestAccComputeV2Instance_forceDelete(t *testing.T) {
   636  	var instance servers.Server
   637  	resource.Test(t, resource.TestCase{
   638  		PreCheck:     func() { testAccPreCheck(t) },
   639  		Providers:    testAccProviders,
   640  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   641  		Steps: []resource.TestStep{
   642  			resource.TestStep{
   643  				Config: testAccComputeV2Instance_forceDelete,
   644  				Check: resource.ComposeTestCheckFunc(
   645  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   646  				),
   647  			},
   648  		},
   649  	})
   650  }
   651  
   652  func TestAccComputeV2Instance_timeout(t *testing.T) {
   653  	var instance servers.Server
   654  	resource.Test(t, resource.TestCase{
   655  		PreCheck:     func() { testAccPreCheck(t) },
   656  		Providers:    testAccProviders,
   657  		CheckDestroy: testAccCheckComputeV2InstanceDestroy,
   658  		Steps: []resource.TestStep{
   659  			resource.TestStep{
   660  				Config: testAccComputeV2Instance_timeout,
   661  				Check: resource.ComposeTestCheckFunc(
   662  					testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
   663  				),
   664  			},
   665  		},
   666  	})
   667  }
   668  
   669  func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error {
   670  	config := testAccProvider.Meta().(*Config)
   671  	computeClient, err := config.computeV2Client(OS_REGION_NAME)
   672  	if err != nil {
   673  		return fmt.Errorf("Error creating OpenStack compute client: %s", err)
   674  	}
   675  
   676  	for _, rs := range s.RootModule().Resources {
   677  		if rs.Type != "openstack_compute_instance_v2" {
   678  			continue
   679  		}
   680  
   681  		_, err := servers.Get(computeClient, rs.Primary.ID).Extract()
   682  		if err == nil {
   683  			return fmt.Errorf("Instance still exists")
   684  		}
   685  	}
   686  
   687  	return nil
   688  }
   689  
   690  func testAccCheckComputeV2InstanceExists(n string, instance *servers.Server) resource.TestCheckFunc {
   691  	return func(s *terraform.State) error {
   692  		rs, ok := s.RootModule().Resources[n]
   693  		if !ok {
   694  			return fmt.Errorf("Not found: %s", n)
   695  		}
   696  
   697  		if rs.Primary.ID == "" {
   698  			return fmt.Errorf("No ID is set")
   699  		}
   700  
   701  		config := testAccProvider.Meta().(*Config)
   702  		computeClient, err := config.computeV2Client(OS_REGION_NAME)
   703  		if err != nil {
   704  			return fmt.Errorf("Error creating OpenStack compute client: %s", err)
   705  		}
   706  
   707  		found, err := servers.Get(computeClient, rs.Primary.ID).Extract()
   708  		if err != nil {
   709  			return err
   710  		}
   711  
   712  		if found.ID != rs.Primary.ID {
   713  			return fmt.Errorf("Instance not found")
   714  		}
   715  
   716  		*instance = *found
   717  
   718  		return nil
   719  	}
   720  }
   721  
   722  func testAccCheckComputeV2InstanceDoesNotExist(n string, instance *servers.Server) resource.TestCheckFunc {
   723  	return func(s *terraform.State) error {
   724  		config := testAccProvider.Meta().(*Config)
   725  		computeClient, err := config.computeV2Client(OS_REGION_NAME)
   726  		if err != nil {
   727  			return fmt.Errorf("Error creating OpenStack compute client: %s", err)
   728  		}
   729  
   730  		_, err = servers.Get(computeClient, instance.ID).Extract()
   731  		if err != nil {
   732  			if _, ok := err.(gophercloud.ErrDefault404); ok {
   733  				return nil
   734  			}
   735  			return err
   736  		}
   737  
   738  		return fmt.Errorf("Instance still exists")
   739  	}
   740  }
   741  
   742  func testAccCheckComputeV2InstanceMetadata(
   743  	instance *servers.Server, k string, v string) resource.TestCheckFunc {
   744  	return func(s *terraform.State) error {
   745  		if instance.Metadata == nil {
   746  			return fmt.Errorf("No metadata")
   747  		}
   748  
   749  		for key, value := range instance.Metadata {
   750  			if k != key {
   751  				continue
   752  			}
   753  
   754  			if v == value {
   755  				return nil
   756  			}
   757  
   758  			return fmt.Errorf("Bad value for %s: %s", k, value)
   759  		}
   760  
   761  		return fmt.Errorf("Metadata not found: %s", k)
   762  	}
   763  }
   764  
   765  func testAccCheckComputeV2InstanceNoMetadataKey(
   766  	instance *servers.Server, k string) resource.TestCheckFunc {
   767  	return func(s *terraform.State) error {
   768  		if instance.Metadata == nil {
   769  			return nil
   770  		}
   771  
   772  		for key, _ := range instance.Metadata {
   773  			if k == key {
   774  				return fmt.Errorf("Metadata found: %s", k)
   775  			}
   776  		}
   777  
   778  		return nil
   779  	}
   780  }
   781  
   782  func testAccCheckComputeV2InstanceVolumeAttachment(
   783  	instance *servers.Server, volume *volumes.Volume) resource.TestCheckFunc {
   784  	return func(s *terraform.State) error {
   785  		var attachments []volumeattach.VolumeAttachment
   786  
   787  		config := testAccProvider.Meta().(*Config)
   788  		computeClient, err := config.computeV2Client(OS_REGION_NAME)
   789  		if err != nil {
   790  			return err
   791  		}
   792  
   793  		err = volumeattach.List(computeClient, instance.ID).EachPage(
   794  			func(page pagination.Page) (bool, error) {
   795  
   796  				actual, err := volumeattach.ExtractVolumeAttachments(page)
   797  				if err != nil {
   798  					return false, fmt.Errorf("Unable to lookup attachment: %s", err)
   799  				}
   800  
   801  				attachments = actual
   802  				return true, nil
   803  			})
   804  
   805  		for _, attachment := range attachments {
   806  			if attachment.VolumeID == volume.ID {
   807  				return nil
   808  			}
   809  		}
   810  
   811  		return fmt.Errorf("Volume not found: %s", volume.ID)
   812  	}
   813  }
   814  
   815  func testAccCheckComputeV2InstanceVolumesDetached(instance *servers.Server) resource.TestCheckFunc {
   816  	return func(s *terraform.State) error {
   817  		var attachments []volumeattach.VolumeAttachment
   818  
   819  		config := testAccProvider.Meta().(*Config)
   820  		computeClient, err := config.computeV2Client(OS_REGION_NAME)
   821  		if err != nil {
   822  			return err
   823  		}
   824  
   825  		err = volumeattach.List(computeClient, instance.ID).EachPage(
   826  			func(page pagination.Page) (bool, error) {
   827  
   828  				actual, err := volumeattach.ExtractVolumeAttachments(page)
   829  				if err != nil {
   830  					return false, fmt.Errorf("Unable to lookup attachment: %s", err)
   831  				}
   832  
   833  				attachments = actual
   834  				return true, nil
   835  			})
   836  
   837  		if len(attachments) > 0 {
   838  			return fmt.Errorf("Volumes are still attached.")
   839  		}
   840  
   841  		return nil
   842  	}
   843  }
   844  
   845  func testAccCheckComputeV2InstanceBootVolumeAttachment(
   846  	instance *servers.Server) resource.TestCheckFunc {
   847  	return func(s *terraform.State) error {
   848  		var attachments []volumeattach.VolumeAttachment
   849  
   850  		config := testAccProvider.Meta().(*Config)
   851  		computeClient, err := config.computeV2Client(OS_REGION_NAME)
   852  		if err != nil {
   853  			return err
   854  		}
   855  
   856  		err = volumeattach.List(computeClient, instance.ID).EachPage(
   857  			func(page pagination.Page) (bool, error) {
   858  
   859  				actual, err := volumeattach.ExtractVolumeAttachments(page)
   860  				if err != nil {
   861  					return false, fmt.Errorf("Unable to lookup attachment: %s", err)
   862  				}
   863  
   864  				attachments = actual
   865  				return true, nil
   866  			})
   867  
   868  		if len(attachments) == 1 {
   869  			return nil
   870  		}
   871  
   872  		return fmt.Errorf("No attached volume found.")
   873  	}
   874  }
   875  
   876  func testAccCheckComputeV2InstanceFloatingIPAttach(
   877  	instance *servers.Server, fip *floatingips.FloatingIP) resource.TestCheckFunc {
   878  	return func(s *terraform.State) error {
   879  		if fip.InstanceID == instance.ID {
   880  			return nil
   881  		}
   882  
   883  		return fmt.Errorf("Floating IP %s was not attached to instance %s", fip.ID, instance.ID)
   884  	}
   885  }
   886  
   887  func testAccCheckComputeV2InstanceInstanceIDsDoNotMatch(
   888  	instance1, instance2 *servers.Server) resource.TestCheckFunc {
   889  	return func(s *terraform.State) error {
   890  		if instance1.ID == instance2.ID {
   891  			return fmt.Errorf("Instance was not recreated.")
   892  		}
   893  
   894  		return nil
   895  	}
   896  }
   897  
   898  func testAccCheckComputeV2InstanceVolumeDetached(instance *servers.Server, volume_id string) resource.TestCheckFunc {
   899  	return func(s *terraform.State) error {
   900  		var attachments []volumeattach.VolumeAttachment
   901  
   902  		rs, ok := s.RootModule().Resources[volume_id]
   903  		if !ok {
   904  			return fmt.Errorf("Not found: %s", volume_id)
   905  		}
   906  
   907  		if rs.Primary.ID == "" {
   908  			return fmt.Errorf("No ID is set")
   909  		}
   910  
   911  		config := testAccProvider.Meta().(*Config)
   912  		computeClient, err := config.computeV2Client(OS_REGION_NAME)
   913  		if err != nil {
   914  			return err
   915  		}
   916  
   917  		err = volumeattach.List(computeClient, instance.ID).EachPage(
   918  			func(page pagination.Page) (bool, error) {
   919  				actual, err := volumeattach.ExtractVolumeAttachments(page)
   920  				if err != nil {
   921  					return false, fmt.Errorf("Unable to lookup attachment: %s", err)
   922  				}
   923  
   924  				attachments = actual
   925  				return true, nil
   926  			})
   927  
   928  		for _, attachment := range attachments {
   929  			if attachment.VolumeID == rs.Primary.ID {
   930  				return fmt.Errorf("Volume is still attached.")
   931  			}
   932  		}
   933  
   934  		return nil
   935  	}
   936  }
   937  
   938  const testAccComputeV2Instance_basic = `
   939  resource "openstack_compute_instance_v2" "instance_1" {
   940    name = "instance_1"
   941    security_groups = ["default"]
   942    metadata {
   943      foo = "bar"
   944    }
   945  }
   946  `
   947  
   948  const testAccComputeV2Instance_volumeAttach = `
   949  resource "openstack_blockstorage_volume_v1" "vol_1" {
   950    name = "vol_1"
   951   	size = 1
   952  }
   953  
   954  resource "openstack_compute_instance_v2" "instance_1" {
   955    name = "instance_1"
   956    security_groups = ["default"]
   957    volume {
   958      volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}"
   959    }
   960  }
   961  `
   962  
   963  const testAccComputeV2Instance_volumeAttachPostCreation_1 = `
   964  resource "openstack_compute_instance_v2" "instance_1" {
   965  	name = "instance_1"
   966  	security_groups = ["default"]
   967  }
   968  `
   969  
   970  const testAccComputeV2Instance_volumeAttachPostCreation_2 = `
   971  resource "openstack_blockstorage_volume_v1" "vol_1" {
   972    name = "vol_1"
   973    size = 1
   974  }
   975  
   976  resource "openstack_compute_instance_v2" "instance_1" {
   977    name = "instance_1"
   978    security_groups = ["default"]
   979    volume {
   980     volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}"
   981    }
   982  }
   983  `
   984  
   985  const testAccComputeV2Instance_volumeDetachPostCreation_1 = `
   986  resource "openstack_blockstorage_volume_v1" "vol_1" {
   987    name = "vol_1"
   988    size = 1
   989  }
   990  
   991  resource "openstack_compute_instance_v2" "instance_1" {
   992    name = "instance_1"
   993    security_groups = ["default"]
   994    volume {
   995      volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}"
   996    }
   997  }
   998  `
   999  
  1000  const testAccComputeV2Instance_volumeDetachPostCreation_2 = `
  1001  resource "openstack_blockstorage_volume_v1" "vol_1" {
  1002    name = "vol_1"
  1003    size = 1
  1004  }
  1005  
  1006  resource "openstack_compute_instance_v2" "instance_1" {
  1007    name = "instance_1"
  1008    security_groups = ["default"]
  1009  }
  1010  `
  1011  
  1012  var testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_1 = fmt.Sprintf(`
  1013  resource "openstack_blockstorage_volume_v1" "root_volume" {
  1014    name = "root_volume"
  1015    size = 1
  1016    image_id = "%s"
  1017  }
  1018  
  1019  resource "openstack_blockstorage_volume_v1" "additional_volume" {
  1020    name = "additional_volume"
  1021    size = 1
  1022  }
  1023  
  1024  resource "openstack_compute_instance_v2" "instance_1" {
  1025    name = "instance_1"
  1026    security_groups = ["default"]
  1027  
  1028    block_device {
  1029      uuid = "${openstack_blockstorage_volume_v1.root_volume.id}"
  1030      source_type = "volume"
  1031      boot_index = 0
  1032      destination_type = "volume"
  1033      delete_on_termination = false
  1034    }
  1035  
  1036    volume {
  1037      volume_id = "${openstack_blockstorage_volume_v1.additional_volume.id}"
  1038  	}
  1039  }
  1040  `, OS_IMAGE_ID)
  1041  
  1042  var testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_2 = fmt.Sprintf(`
  1043  resource "openstack_blockstorage_volume_v1" "root_volume" {
  1044    name = "root_volume"
  1045    size = 1
  1046    image_id = "%s"
  1047  }
  1048  
  1049  resource "openstack_blockstorage_volume_v1" "additional_volume" {
  1050    name = "additional_volume"
  1051    size = 1
  1052  }
  1053  
  1054  resource "openstack_compute_instance_v2" "instance_1" {
  1055    name = "instance_1"
  1056    security_groups = ["default"]
  1057  
  1058    block_device {
  1059      uuid = "${openstack_blockstorage_volume_v1.root_volume.id}"
  1060      source_type = "volume"
  1061      boot_index = 0
  1062      destination_type = "volume"
  1063      delete_on_termination = false
  1064    }
  1065  }
  1066  `, OS_IMAGE_ID)
  1067  
  1068  var testAccComputeV2Instance_volumeAttachInstanceDelete_1 = fmt.Sprintf(`
  1069  resource "openstack_blockstorage_volume_v1" "root_volume" {
  1070    name = "root_volume"
  1071    size = 1
  1072    image_id = "%s"
  1073  }
  1074  
  1075  resource "openstack_blockstorage_volume_v1" "additional_volume" {
  1076    name = "additional_volume"
  1077    size = 1
  1078  }
  1079  
  1080  resource "openstack_compute_instance_v2" "instance_1" {
  1081    name = "instance_1"
  1082    security_groups = ["default"]
  1083  
  1084    block_device {
  1085      uuid = "${openstack_blockstorage_volume_v1.root_volume.id}"
  1086      source_type = "volume"
  1087      boot_index = 0
  1088      destination_type = "volume"
  1089      delete_on_termination = false
  1090    }
  1091  
  1092    volume {
  1093      volume_id = "${openstack_blockstorage_volume_v1.additional_volume.id}"
  1094    }
  1095  }
  1096  `, OS_IMAGE_ID)
  1097  
  1098  var testAccComputeV2Instance_volumeAttachInstanceDelete_2 = fmt.Sprintf(`
  1099  resource "openstack_blockstorage_volume_v1" "root_volume" {
  1100    name = "root_volume"
  1101    size = 1
  1102    image_id = "%s"
  1103  }
  1104  
  1105  resource "openstack_blockstorage_volume_v1" "additional_volume" {
  1106    name = "additional_volume"
  1107    size = 1
  1108  }
  1109  `, OS_IMAGE_ID)
  1110  
  1111  const testAccComputeV2Instance_volumeAttachToNewInstance_1 = `
  1112  resource "openstack_blockstorage_volume_v1" "volume_1" {
  1113    name = "volume_1"
  1114    size = 1
  1115  }
  1116  
  1117  resource "openstack_compute_instance_v2" "instance_1" {
  1118    name = "instance_1"
  1119    security_groups = ["default"]
  1120  
  1121    volume {
  1122      volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}"
  1123    }
  1124  }
  1125  
  1126  resource "openstack_compute_instance_v2" "instance_2" {
  1127    depends_on = ["openstack_compute_instance_v2.instance_1"]
  1128    name = "instance_2"
  1129    security_groups = ["default"]
  1130  }
  1131  `
  1132  
  1133  const testAccComputeV2Instance_volumeAttachToNewInstance_2 = `
  1134  resource "openstack_blockstorage_volume_v1" "volume_1" {
  1135    name = "volume_1"
  1136    size = 1
  1137  }
  1138  
  1139  resource "openstack_compute_instance_v2" "instance_1" {
  1140    name = "instance_1"
  1141    security_groups = ["default"]
  1142  }
  1143  
  1144  resource "openstack_compute_instance_v2" "instance_2" {
  1145    depends_on = ["openstack_compute_instance_v2.instance_1"]
  1146    name = "instance_2"
  1147    security_groups = ["default"]
  1148  
  1149    volume {
  1150      volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}"
  1151    }
  1152  }
  1153  	`
  1154  
  1155  const testAccComputeV2Instance_floatingIPAttachGlobally = `
  1156  resource "openstack_compute_floatingip_v2" "fip_1" {
  1157  }
  1158  
  1159  resource "openstack_compute_instance_v2" "instance_1" {
  1160    name = "instance_1"
  1161    security_groups = ["default"]
  1162    floating_ip = "${openstack_compute_floatingip_v2.fip_1.address}"
  1163  }
  1164  `
  1165  
  1166  var testAccComputeV2Instance_floatingIPAttachToNetwork = fmt.Sprintf(`
  1167  resource "openstack_compute_floatingip_v2" "fip_1" {
  1168  }
  1169  
  1170  resource "openstack_compute_instance_v2" "instance_1" {
  1171    name = "instance_1"
  1172    security_groups = ["default"]
  1173  
  1174    network {
  1175      uuid = "%s"
  1176      floating_ip = "${openstack_compute_floatingip_v2.fip_1.address}"
  1177      access_network = true
  1178    }
  1179  }
  1180  `, OS_NETWORK_ID)
  1181  
  1182  var testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_1 = fmt.Sprintf(`
  1183  resource "openstack_compute_floatingip_v2" "fip_1" {
  1184  }
  1185  
  1186  resource "openstack_compute_floatingip_v2" "fip_2" {
  1187  }
  1188  
  1189  resource "openstack_compute_instance_v2" "instance_1" {
  1190    name = "instance_1"
  1191    security_groups = ["default"]
  1192  
  1193    network {
  1194      uuid = "%s"
  1195      floating_ip = "${openstack_compute_floatingip_v2.fip_1.address}"
  1196      access_network = true
  1197    }
  1198  }
  1199  `, OS_NETWORK_ID)
  1200  
  1201  var testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_2 = fmt.Sprintf(`
  1202  resource "openstack_compute_floatingip_v2" "fip_1" {
  1203  }
  1204  
  1205  resource "openstack_compute_floatingip_v2" "fip_2" {
  1206  }
  1207  
  1208  resource "openstack_compute_instance_v2" "instance_1" {
  1209    name = "instance_1"
  1210    security_groups = ["default"]
  1211  
  1212    network {
  1213      uuid = "%s"
  1214      floating_ip = "${openstack_compute_floatingip_v2.fip_2.address}"
  1215      access_network = true
  1216    }
  1217  }
  1218  `, OS_NETWORK_ID)
  1219  
  1220  const testAccComputeV2Instance_secgroupMulti = `
  1221  resource "openstack_compute_secgroup_v2" "secgroup_1" {
  1222    name = "secgroup_1"
  1223    description = "a security group"
  1224    rule {
  1225      from_port = 22
  1226      to_port = 22
  1227      ip_protocol = "tcp"
  1228      cidr = "0.0.0.0/0"
  1229    }
  1230  }
  1231  
  1232  resource "openstack_compute_instance_v2" "instance_1" {
  1233    name = "instance_1"
  1234    security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"]
  1235  }
  1236  `
  1237  
  1238  const testAccComputeV2Instance_secgroupMultiUpdate_1 = `
  1239  resource "openstack_compute_secgroup_v2" "secgroup_1" {
  1240    name = "secgroup_1"
  1241    description = "a security group"
  1242    rule {
  1243      from_port = 22
  1244      to_port = 22
  1245      ip_protocol = "tcp"
  1246      cidr = "0.0.0.0/0"
  1247    }
  1248  }
  1249  
  1250  resource "openstack_compute_secgroup_v2" "secgroup_2" {
  1251    name = "secgroup_2"
  1252    description = "another security group"
  1253    rule {
  1254      from_port = 80
  1255      to_port = 80
  1256      ip_protocol = "tcp"
  1257      cidr = "0.0.0.0/0"
  1258    }
  1259  }
  1260  
  1261  resource "openstack_compute_instance_v2" "instance_1" {
  1262    name = "instance_1"
  1263    security_groups = ["default"]
  1264  }
  1265  `
  1266  
  1267  const testAccComputeV2Instance_secgroupMultiUpdate_2 = `
  1268  resource "openstack_compute_secgroup_v2" "secgroup_1" {
  1269    name = "secgroup_1"
  1270    description = "a security group"
  1271    rule {
  1272      from_port = 22
  1273      to_port = 22
  1274      ip_protocol = "tcp"
  1275      cidr = "0.0.0.0/0"
  1276    }
  1277  }
  1278  
  1279  resource "openstack_compute_secgroup_v2" "secgroup_2" {
  1280    name = "secgroup_2"
  1281    description = "another security group"
  1282    rule {
  1283      from_port = 80
  1284      to_port = 80
  1285      ip_protocol = "tcp"
  1286      cidr = "0.0.0.0/0"
  1287    }
  1288  }
  1289  
  1290  resource "openstack_compute_instance_v2" "instance_1" {
  1291    name = "instance_1"
  1292    security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}", "${openstack_compute_secgroup_v2.secgroup_2.name}"]
  1293  }
  1294  `
  1295  
  1296  var testAccComputeV2Instance_bootFromVolumeImage = fmt.Sprintf(`
  1297  resource "openstack_compute_instance_v2" "instance_1" {
  1298    name = "instance_1"
  1299    security_groups = ["default"]
  1300    block_device {
  1301      uuid = "%s"
  1302      source_type = "image"
  1303      volume_size = 5
  1304      boot_index = 0
  1305      destination_type = "volume"
  1306      delete_on_termination = true
  1307    }
  1308  }
  1309  `, OS_IMAGE_ID)
  1310  
  1311  var testAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume = fmt.Sprintf(`
  1312  resource "openstack_blockstorage_volume_v1" "volume_1" {
  1313    name = "volume_1"
  1314    size = 1
  1315  }
  1316  
  1317  resource "openstack_compute_instance_v2" "instance_1" {
  1318    name = "instance_1"
  1319    security_groups = ["default"]
  1320    block_device {
  1321      uuid = "%s"
  1322      source_type = "image"
  1323      volume_size = 2
  1324      boot_index = 0
  1325      destination_type = "volume"
  1326      delete_on_termination = true
  1327    }
  1328  
  1329    volume {
  1330      volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}"
  1331    }
  1332  }
  1333  `, OS_IMAGE_ID)
  1334  
  1335  var testAccComputeV2Instance_bootFromVolumeVolume = fmt.Sprintf(`
  1336  resource "openstack_blockstorage_volume_v1" "vol_1" {
  1337    name = "vol_1"
  1338    size = 5
  1339    image_id = "%s"
  1340  }
  1341  
  1342  resource "openstack_compute_instance_v2" "instance_1" {
  1343    name = "instance_1"
  1344    security_groups = ["default"]
  1345    block_device {
  1346      uuid = "${openstack_blockstorage_volume_v1.vol_1.id}"
  1347      source_type = "volume"
  1348      boot_index = 0
  1349      destination_type = "volume"
  1350      delete_on_termination = true
  1351    }
  1352  }
  1353  `, OS_IMAGE_ID)
  1354  
  1355  var testAccComputeV2Instance_bootFromVolumeForceNew_1 = fmt.Sprintf(`
  1356  resource "openstack_compute_instance_v2" "instance_1" {
  1357    name = "instance_1"
  1358    security_groups = ["default"]
  1359    block_device {
  1360      uuid = "%s"
  1361      source_type = "image"
  1362      volume_size = 5
  1363      boot_index = 0
  1364      destination_type = "volume"
  1365      delete_on_termination = true
  1366    }
  1367  }
  1368  `, OS_IMAGE_ID)
  1369  
  1370  var testAccComputeV2Instance_bootFromVolumeForceNew_2 = fmt.Sprintf(`
  1371  resource "openstack_compute_instance_v2" "instance_1" {
  1372    name = "instance_1"
  1373    security_groups = ["default"]
  1374    block_device {
  1375      uuid = "%s"
  1376      source_type = "image"
  1377      volume_size = 4
  1378      boot_index = 0
  1379      destination_type = "volume"
  1380      delete_on_termination = true
  1381    }
  1382  }
  1383  `, OS_IMAGE_ID)
  1384  
  1385  var testAccComputeV2Instance_blockDeviceNewVolume = fmt.Sprintf(`
  1386  resource "openstack_compute_instance_v2" "instance_1" {
  1387    name = "instance_1"
  1388    security_groups = ["default"]
  1389    block_device {
  1390      uuid = "%s"
  1391      source_type = "image"
  1392      destination_type = "local"
  1393      boot_index = 0
  1394      delete_on_termination = true
  1395    }
  1396    block_device {
  1397      source_type = "blank"
  1398      destination_type = "volume"
  1399      volume_size = 1
  1400      boot_index = 1
  1401      delete_on_termination = true
  1402    }
  1403  }
  1404  `, OS_IMAGE_ID)
  1405  
  1406  var testAccComputeV2Instance_blockDeviceExistingVolume = fmt.Sprintf(`
  1407  resource "openstack_blockstorage_volume_v1" "volume_1" {
  1408    name = "volume_1"
  1409    size = 1
  1410  }
  1411  
  1412  resource "openstack_compute_instance_v2" "instance_1" {
  1413    name = "instance_1"
  1414    security_groups = ["default"]
  1415    block_device {
  1416      uuid = "%s"
  1417      source_type = "image"
  1418      destination_type = "local"
  1419      boot_index = 0
  1420      delete_on_termination = true
  1421    }
  1422    block_device {
  1423      uuid = "${openstack_blockstorage_volume_v1.volume_1.id}"
  1424      source_type = "volume"
  1425      destination_type = "volume"
  1426      boot_index = 1
  1427      delete_on_termination = true
  1428    }
  1429  }
  1430  `, OS_IMAGE_ID)
  1431  
  1432  const testAccComputeV2Instance_personality = `
  1433  resource "openstack_compute_instance_v2" "instance_1" {
  1434    name = "instance_1"
  1435    security_groups = ["default"]
  1436    personality {
  1437      file = "/tmp/foobar.txt"
  1438      content = "happy"
  1439    }
  1440    personality {
  1441      file = "/tmp/barfoo.txt"
  1442      content = "angry"
  1443    }
  1444  }
  1445  `
  1446  
  1447  var testAccComputeV2Instance_multiEphemeral = fmt.Sprintf(`
  1448  resource "openstack_compute_instance_v2" "instance_1" {
  1449    name = "terraform-test"
  1450    security_groups = ["default"]
  1451    block_device {
  1452      boot_index = 0
  1453      delete_on_termination = true
  1454      destination_type = "local"
  1455      source_type = "image"
  1456      uuid = "%s"
  1457    }
  1458    block_device {
  1459      boot_index = -1
  1460      delete_on_termination = true
  1461      destination_type = "local"
  1462      source_type = "blank"
  1463      volume_size = 1
  1464    }
  1465    block_device {
  1466      boot_index = -1
  1467      delete_on_termination = true
  1468      destination_type = "local"
  1469      source_type = "blank"
  1470      volume_size = 1
  1471    }
  1472  }
  1473  `, OS_IMAGE_ID)
  1474  
  1475  var testAccComputeV2Instance_accessIPv4 = fmt.Sprintf(`
  1476  resource "openstack_compute_floatingip_v2" "myip" {
  1477  }
  1478  
  1479  resource "openstack_networking_network_v2" "network_1" {
  1480    name = "network_1"
  1481  }
  1482  
  1483  resource "openstack_networking_subnet_v2" "subnet_1" {
  1484    name = "subnet_1"
  1485    network_id = "${openstack_networking_network_v2.network_1.id}"
  1486    cidr = "192.168.1.0/24"
  1487    ip_version = 4
  1488    enable_dhcp = true
  1489    no_gateway = true
  1490  }
  1491  
  1492  resource "openstack_compute_instance_v2" "instance_1" {
  1493    depends_on = ["openstack_networking_subnet_v2.subnet_1"]
  1494  
  1495    name = "instance_1"
  1496    security_groups = ["default"]
  1497    floating_ip = "${openstack_compute_floatingip_v2.myip.address}"
  1498  
  1499    network {
  1500      uuid = "%s"
  1501    }
  1502  
  1503    network {
  1504      uuid = "${openstack_networking_network_v2.network_1.id}"
  1505      fixed_ip_v4 = "192.168.1.100"
  1506      access_network = true
  1507    }
  1508  }
  1509  `, OS_NETWORK_ID)
  1510  
  1511  var testAccComputeV2Instance_changeFixedIP_1 = fmt.Sprintf(`
  1512  resource "openstack_compute_instance_v2" "instance_1" {
  1513    name = "instance_1"
  1514    security_groups = ["default"]
  1515    network {
  1516      uuid = "%s"
  1517      fixed_ip_v4 = "10.0.0.24"
  1518    }
  1519  }
  1520  `, OS_NETWORK_ID)
  1521  
  1522  var testAccComputeV2Instance_changeFixedIP_2 = fmt.Sprintf(`
  1523  resource "openstack_compute_instance_v2" "instance_1" {
  1524    name = "instance_1"
  1525    security_groups = ["default"]
  1526    network {
  1527      uuid = "%s"
  1528      fixed_ip_v4 = "10.0.0.25"
  1529    }
  1530  }
  1531  `, OS_NETWORK_ID)
  1532  
  1533  const testAccComputeV2Instance_stopBeforeDestroy = `
  1534  resource "openstack_compute_instance_v2" "instance_1" {
  1535    name = "instance_1"
  1536    security_groups = ["default"]
  1537    stop_before_destroy = true
  1538  }
  1539  `
  1540  
  1541  const testAccComputeV2Instance_metadataRemove_1 = `
  1542  resource "openstack_compute_instance_v2" "instance_1" {
  1543    name = "instance_1"
  1544    security_groups = ["default"]
  1545    metadata {
  1546      foo = "bar"
  1547      abc = "def"
  1548    }
  1549  }
  1550  `
  1551  
  1552  const testAccComputeV2Instance_metadataRemove_2 = `
  1553  resource "openstack_compute_instance_v2" "instance_1" {
  1554    name = "instance_1"
  1555    security_groups = ["default"]
  1556    metadata {
  1557      foo = "bar"
  1558      ghi = "jkl"
  1559    }
  1560  }
  1561  `
  1562  
  1563  const testAccComputeV2Instance_forceDelete = `
  1564  resource "openstack_compute_instance_v2" "instance_1" {
  1565    name = "instance_1"
  1566    security_groups = ["default"]
  1567    force_delete = true
  1568  }
  1569  `
  1570  
  1571  const testAccComputeV2Instance_timeout = `
  1572  resource "openstack_compute_instance_v2" "instance_1" {
  1573    name = "instance_1"
  1574    security_groups = ["default"]
  1575  
  1576    timeouts {
  1577      create = "10m"
  1578    }
  1579  }
  1580  `