@@ -150,6 +150,68 @@ func TestAccCloudStackInstance_keyPair(t *testing.T) {
150150 })
151151}
152152
153+ func TestAccCloudStackInstance_keyPairs (t * testing.T ) {
154+ var instance cloudstack.VirtualMachine
155+
156+ resource .Test (t , resource.TestCase {
157+ PreCheck : func () { testAccPreCheck (t ) },
158+ Providers : testAccProviders ,
159+ CheckDestroy : testAccCheckCloudStackInstanceDestroy ,
160+ Steps : []resource.TestStep {
161+ {
162+ Config : testAccCloudStackInstance_keyPairs ,
163+ Check : resource .ComposeTestCheckFunc (
164+ testAccCheckCloudStackInstanceExists ("cloudstack_instance.foobar" , & instance ),
165+ resource .TestCheckResourceAttr ("cloudstack_instance.foobar" , "keypairs.#" , "2" ), // Expecting 2 key pairs
166+ resource .TestCheckResourceAttr ("cloudstack_instance.foobar" , "keypairs.0" , "terraform-test-keypair-foo" ),
167+ resource .TestCheckResourceAttr ("cloudstack_instance.foobar" , "keypairs.1" , "terraform-test-keypair-bar" ),
168+ ),
169+ },
170+ },
171+ })
172+ }
173+
174+ func TestAccCloudStackInstance_keyPair_update (t * testing.T ) {
175+ var instance cloudstack.VirtualMachine
176+
177+ resource .Test (t , resource.TestCase {
178+ PreCheck : func () { testAccPreCheck (t ) },
179+ Providers : testAccProviders ,
180+ CheckDestroy : testAccCheckCloudStackInstanceDestroy ,
181+ Steps : []resource.TestStep {
182+ {
183+ Config : testAccCloudStackInstance_keyPair ,
184+ Check : resource .ComposeTestCheckFunc (
185+ testAccCheckCloudStackInstanceExists (
186+ "cloudstack_instance.foobar" , & instance ),
187+ resource .TestCheckResourceAttr (
188+ "cloudstack_instance.foobar" , "keypair" , "terraform-test-keypair" ),
189+ ),
190+ },
191+
192+ {
193+ Config : testAccCloudStackInstance_keyPairs ,
194+ Check : resource .ComposeTestCheckFunc (
195+ testAccCheckCloudStackInstanceExists ("cloudstack_instance.foobar" , & instance ),
196+ resource .TestCheckResourceAttr ("cloudstack_instance.foobar" , "keypairs.#" , "2" ), // Expecting 2 key pairs
197+ resource .TestCheckResourceAttr ("cloudstack_instance.foobar" , "keypairs.0" , "terraform-test-keypair-foo" ),
198+ resource .TestCheckResourceAttr ("cloudstack_instance.foobar" , "keypairs.1" , "terraform-test-keypair-bar" ),
199+ ),
200+ },
201+
202+ {
203+ Config : testAccCloudStackInstance_keyPair ,
204+ Check : resource .ComposeTestCheckFunc (
205+ testAccCheckCloudStackInstanceExists (
206+ "cloudstack_instance.foobar" , & instance ),
207+ resource .TestCheckResourceAttr (
208+ "cloudstack_instance.foobar" , "keypair" , "terraform-test-keypair" ),
209+ ),
210+ },
211+ },
212+ })
213+ }
214+
153215func TestAccCloudStackInstance_project (t * testing.T ) {
154216 var instance cloudstack.VirtualMachine
155217
@@ -416,6 +478,33 @@ resource "cloudstack_instance" "foobar" {
416478 expunge = true
417479}`
418480
481+ const testAccCloudStackInstance_keyPairs = `
482+ resource "cloudstack_network" "foo" {
483+ name = "terraform-network"
484+ cidr = "10.1.1.0/24"
485+ network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
486+ zone = "Sandbox-simulator"
487+ }
488+
489+ resource "cloudstack_ssh_keypair" "foo" {
490+ name = "terraform-test-keypair-foo"
491+ }
492+
493+ resource "cloudstack_ssh_keypair" "bar" {
494+ name = "terraform-test-keypair-bar"
495+ }
496+
497+ resource "cloudstack_instance" "foobar" {
498+ name = "terraform-test"
499+ display_name = "terraform-test"
500+ service_offering= "Small Instance"
501+ network_id = "${cloudstack_network.foo.id}"
502+ template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
503+ zone = "Sandbox-simulator"
504+ keypairs = ["${cloudstack_ssh_keypair.foo.name}", "${cloudstack_ssh_keypair.bar.name}"]
505+ expunge = true
506+ }`
507+
419508const testAccCloudStackInstance_project = `
420509resource "cloudstack_network" "foo" {
421510 name = "terraform-network"
0 commit comments