Merge pull request #2281 from svanharmelen/f-provider-cloudstack

provider/cloudstack: updating and tweaking tests and docs
This commit is contained in:
Sander van Harmelen 2015-06-09 12:44:22 +02:00
commit aed44622b1
26 changed files with 311 additions and 310 deletions

View File

@ -158,7 +158,7 @@ func testAccCheckAzureDataDiskDestroy(s *terraform.State) error {
_, err = virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun) _, err = virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun)
if err == nil { if err == nil {
return fmt.Errorf("Resource %s still exists", rs.Primary.ID) return fmt.Errorf("Data disk %s still exists", rs.Primary.ID)
} }
if !management.IsResourceNotFoundError(err) { if !management.IsResourceNotFoundError(err) {

View File

@ -297,7 +297,7 @@ func testAccCheckAzureInstanceDestroy(s *terraform.State) error {
_, err := hostedservice.NewClient(mc).GetHostedService(rs.Primary.ID) _, err := hostedservice.NewClient(mc).GetHostedService(rs.Primary.ID)
if err == nil { if err == nil {
return fmt.Errorf("Resource %s still exists", rs.Primary.ID) return fmt.Errorf("Instance %s still exists", rs.Primary.ID)
} }
if !management.IsResourceNotFoundError(err) { if !management.IsResourceNotFoundError(err) {

View File

@ -217,7 +217,7 @@ func testAccCheckAzureSecurityGroupDestroy(s *terraform.State) error {
_, err := networksecuritygroup.NewClient(mc).GetNetworkSecurityGroup(rs.Primary.ID) _, err := networksecuritygroup.NewClient(mc).GetNetworkSecurityGroup(rs.Primary.ID)
if err == nil { if err == nil {
return fmt.Errorf("Resource %s still exists", rs.Primary.ID) return fmt.Errorf("Network Security Group %s still exists", rs.Primary.ID)
} }
if !management.IsResourceNotFoundError(err) { if !management.IsResourceNotFoundError(err) {

View File

@ -190,7 +190,7 @@ func testAccCheckAzureVirtualNetworkDestroy(s *terraform.State) error {
for _, n := range nc.Configuration.VirtualNetworkSites { for _, n := range nc.Configuration.VirtualNetworkSites {
if n.Name == rs.Primary.ID { if n.Name == rs.Primary.ID {
return fmt.Errorf("Resource %s still exists", rs.Primary.ID) return fmt.Errorf("Virtual Network %s still exists", rs.Primary.ID)
} }
} }
} }

View File

@ -39,7 +39,7 @@ func testSetValueOnResourceData(t *testing.T) {
} }
} }
func testSetUuidOnResourceData(t *testing.T) { func testSetUUIDOnResourceData(t *testing.T) {
d := schema.ResourceData{} d := schema.ResourceData{}
d.Set("id", "54711781-274e-41b2-83c0-17194d0108f7") d.Set("id", "54711781-274e-41b2-83c0-17194d0108f7")
@ -60,35 +60,116 @@ func testAccPreCheck(t *testing.T) {
if v := os.Getenv("CLOUDSTACK_SECRET_KEY"); v == "" { if v := os.Getenv("CLOUDSTACK_SECRET_KEY"); v == "" {
t.Fatal("CLOUDSTACK_SECRET_KEY must be set for acceptance tests") t.Fatal("CLOUDSTACK_SECRET_KEY must be set for acceptance tests")
} }
if v := os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS"); v == "" {
t.Fatal("CLOUDSTACK_2ND_NIC_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK"); v == "" {
t.Fatal("CLOUDSTACK_2ND_NIC_NETWORK must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_DISK_OFFERING_1"); v == "" {
t.Fatal("CLOUDSTACK_DISK_OFFERING_1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_DISK_OFFERING_2"); v == "" {
t.Fatal("CLOUDSTACK_DISK_OFFERING_2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_HYPERVISOR"); v == "" {
t.Fatal("CLOUDSTACK_HYPERVISOR must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1"); v == "" {
t.Fatal("CLOUDSTACK_SERVICE_OFFERING_1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2"); v == "" {
t.Fatal("CLOUDSTACK_SERVICE_OFFERING_2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_1"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_1_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_2"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_2_CIDR"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_2_CIDR must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_2_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS"); v == "" {
t.Fatal("CLOUDSTACK_NETWORK_2_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_CIDR_1"); v == "" {
t.Fatal("CLOUDSTACK_VPC_CIDR_1 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_CIDR_2"); v == "" {
t.Fatal("CLOUDSTACK_VPC_CIDR_2 must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_OFFERING"); v == "" {
t.Fatal("CLOUDSTACK_VPC_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR"); v == "" {
t.Fatal("CLOUDSTACK_VPC_NETWORK_CIDR must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING"); v == "" {
t.Fatal("CLOUDSTACK_VPC_NETWORK_OFFERING must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS"); v == "" {
t.Fatal("CLOUDSTACK_PUBLIC_IPADDRESS must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_SSH_KEYPAIR"); v == "" {
t.Fatal("CLOUDSTACK_SSH_KEYPAIR must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY"); v == "" {
t.Fatal("CLOUDSTACK_SSH_PUBLIC_KEY must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_TEMPLATE"); v == "" {
t.Fatal("CLOUDSTACK_TEMPLATE must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT"); v == "" {
t.Fatal("CLOUDSTACK_TEMPLATE_FORMAT must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_TEMPLATE_URL"); v == "" {
t.Fatal("CLOUDSTACK_TEMPLATE_URL must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE"); v == "" {
t.Fatal("CLOUDSTACK_TEMPLATE_OS_TYPE must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PROJECT_NAME"); v == "" {
t.Fatal("CLOUDSTACK_PROJECT_NAME must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_PROJECT_NETWORK"); v == "" {
t.Fatal("CLOUDSTACK_PROJECT_NETWORK must be set for acceptance tests")
}
if v := os.Getenv("CLOUDSTACK_ZONE"); v == "" {
t.Fatal("CLOUDSTACK_ZONE must be set for acceptance tests")
}
} }
// SET THESE VALUES IN ORDER TO RUN THE ACC TESTS!! var CLOUDSTACK_2ND_NIC_IPADDRESS = os.Getenv("CLOUDSTACK_2ND_NIC_IPADDRESS")
var CLOUDSTACK_2ND_NIC_IPADDRESS = "" var CLOUDSTACK_2ND_NIC_NETWORK = os.Getenv("CLOUDSTACK_2ND_NIC_NETWORK")
var CLOUDSTACK_2ND_NIC_NETWORK = "" var CLOUDSTACK_DISK_OFFERING_1 = os.Getenv("CLOUDSTACK_DISK_OFFERING_1")
var CLOUDSTACK_DISK_OFFERING_1 = "" var CLOUDSTACK_DISK_OFFERING_2 = os.Getenv("CLOUDSTACK_DISK_OFFERING_2")
var CLOUDSTACK_DISK_OFFERING_2 = "" var CLOUDSTACK_HYPERVISOR = os.Getenv("CLOUDSTACK_HYPERVISOR")
var CLOUDSTACK_HYPERVISOR = "" var CLOUDSTACK_SERVICE_OFFERING_1 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_1")
var CLOUDSTACK_SERVICE_OFFERING_1 = "" var CLOUDSTACK_SERVICE_OFFERING_2 = os.Getenv("CLOUDSTACK_SERVICE_OFFERING_2")
var CLOUDSTACK_SERVICE_OFFERING_2 = "" var CLOUDSTACK_NETWORK_1 = os.Getenv("CLOUDSTACK_NETWORK_1")
var CLOUDSTACK_NETWORK_1 = "" var CLOUDSTACK_NETWORK_1_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_1_IPADDRESS")
var CLOUDSTACK_NETWORK_1_IPADDRESS = "" var CLOUDSTACK_NETWORK_2 = os.Getenv("CLOUDSTACK_NETWORK_2")
var CLOUDSTACK_NETWORK_2 = "" var CLOUDSTACK_NETWORK_2_CIDR = os.Getenv("CLOUDSTACK_NETWORK_2_CIDR")
var CLOUDSTACK_NETWORK_2_CIDR = "" var CLOUDSTACK_NETWORK_2_OFFERING = os.Getenv("CLOUDSTACK_NETWORK_2_OFFERING")
var CLOUDSTACK_NETWORK_2_OFFERING = "" var CLOUDSTACK_NETWORK_2_IPADDRESS = os.Getenv("CLOUDSTACK_NETWORK_2_IPADDRESS")
var CLOUDSTACK_NETWORK_2_IPADDRESS = "" var CLOUDSTACK_VPC_CIDR_1 = os.Getenv("CLOUDSTACK_VPC_CIDR_1")
var CLOUDSTACK_VPC_CIDR_1 = "" var CLOUDSTACK_VPC_CIDR_2 = os.Getenv("CLOUDSTACK_VPC_CIDR_2")
var CLOUDSTACK_VPC_CIDR_2 = "" var CLOUDSTACK_VPC_OFFERING = os.Getenv("CLOUDSTACK_VPC_OFFERING")
var CLOUDSTACK_VPC_OFFERING = "" var CLOUDSTACK_VPC_NETWORK_CIDR = os.Getenv("CLOUDSTACK_VPC_NETWORK_CIDR")
var CLOUDSTACK_VPC_NETWORK_CIDR = "" var CLOUDSTACK_VPC_NETWORK_OFFERING = os.Getenv("CLOUDSTACK_VPC_NETWORK_OFFERING")
var CLOUDSTACK_VPC_NETWORK_OFFERING = "" var CLOUDSTACK_PUBLIC_IPADDRESS = os.Getenv("CLOUDSTACK_PUBLIC_IPADDRESS")
var CLOUDSTACK_PUBLIC_IPADDRESS = "" var CLOUDSTACK_SSH_PUBLIC_KEY = os.Getenv("CLOUDSTACK_SSH_PUBLIC_KEY")
var CLOUDSTACK_SSH_KEYPAIR = "" var CLOUDSTACK_TEMPLATE = os.Getenv("CLOUDSTACK_TEMPLATE")
var CLOUDSTACK_SSH_PUBLIC_KEY = "" var CLOUDSTACK_TEMPLATE_FORMAT = os.Getenv("CLOUDSTACK_TEMPLATE_FORMAT")
var CLOUDSTACK_TEMPLATE = "" var CLOUDSTACK_TEMPLATE_URL = os.Getenv("CLOUDSTACK_TEMPLATE_URL")
var CLOUDSTACK_TEMPLATE_FORMAT = "" var CLOUDSTACK_TEMPLATE_OS_TYPE = os.Getenv("CLOUDSTACK_TEMPLATE_OS_TYPE")
var CLOUDSTACK_TEMPLATE_URL = "" var CLOUDSTACK_PROJECT_NAME = os.Getenv("CLOUDSTACK_PROJECT_NAME")
var CLOUDSTACK_TEMPLATE_OS_TYPE = "" var CLOUDSTACK_PROJECT_NETWORK = os.Getenv("CLOUDSTACK_PROJECT_NETWORK")
var CLOUDSTACK_ZONE = "" var CLOUDSTACK_ZONE = os.Getenv("CLOUDSTACK_ZONE")
var CLOUDSTACK_PROJECT_NAME = ""
var CLOUDSTACK_PROJECT_ID = ""

View File

@ -35,7 +35,7 @@ func TestAccCloudStackDisk_device(t *testing.T) {
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckCloudStackDiskDestroyAdvanced, CheckDestroy: testAccCheckCloudStackDiskDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCloudStackDisk_device, Config: testAccCloudStackDisk_device,
@ -57,7 +57,7 @@ func TestAccCloudStackDisk_update(t *testing.T) {
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckCloudStackDiskDestroyAdvanced, CheckDestroy: testAccCheckCloudStackDiskDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCloudStackDisk_update, Config: testAccCloudStackDisk_update,
@ -151,57 +151,9 @@ func testAccCheckCloudStackDiskDestroy(s *terraform.State) error {
return fmt.Errorf("No disk ID is set") return fmt.Errorf("No disk ID is set")
} }
p := cs.Volume.NewDeleteVolumeParams(rs.Primary.ID) _, _, err := cs.Volume.GetVolumeByID(rs.Primary.ID)
_, err := cs.Volume.DeleteVolume(p) if err == nil {
return fmt.Errorf("Disk %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting disk (%s): %s",
rs.Primary.ID, err)
}
}
return nil
}
func testAccCheckCloudStackDiskDestroyAdvanced(s *terraform.State) error {
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
for _, rs := range s.RootModule().Resources {
if rs.Type != "cloudstack_disk" {
continue
}
if rs.Primary.ID == "" {
return fmt.Errorf("No disk ID is set")
}
p := cs.Volume.NewDeleteVolumeParams(rs.Primary.ID)
_, err := cs.Volume.DeleteVolume(p)
if err != nil {
return fmt.Errorf(
"Error deleting disk (%s): %s",
rs.Primary.ID, err)
}
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "cloudstack_instance" {
continue
}
if rs.Primary.ID == "" {
return fmt.Errorf("No instance ID is set")
}
p := cs.VirtualMachine.NewDestroyVirtualMachineParams(rs.Primary.ID)
_, err := cs.VirtualMachine.DestroyVirtualMachine(p)
if err != nil {
return fmt.Errorf(
"Error deleting instance (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -154,11 +154,9 @@ func testAccCheckCloudStackEgressFirewallDestroy(s *terraform.State) error {
continue continue
} }
p := cs.Firewall.NewDeleteEgressFirewallRuleParams(uuid) _, _, err := cs.Firewall.GetEgressFirewallRuleByID(uuid)
_, err := cs.Firewall.DeleteEgressFirewallRule(p) if err == nil {
return fmt.Errorf("Egress rule %s still exists", rs.Primary.ID)
if err != nil {
return err
} }
} }
} }

View File

@ -148,11 +148,9 @@ func testAccCheckCloudStackFirewallDestroy(s *terraform.State) error {
continue continue
} }
p := cs.Firewall.NewDeleteFirewallRuleParams(uuid) _, _, err := cs.Firewall.GetFirewallRuleByID(uuid)
_, err := cs.Firewall.DeleteFirewallRule(p) if err == nil {
return fmt.Errorf("Firewall rule %s still exists", rs.Primary.ID)
if err != nil {
return err
} }
} }
} }

View File

@ -56,6 +56,12 @@ func resourceCloudStackInstance() *schema.Resource {
ForceNew: true, ForceNew: true,
}, },
"project": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"zone": &schema.Schema{ "zone": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
@ -87,13 +93,6 @@ func resourceCloudStackInstance() *schema.Resource {
Optional: true, Optional: true,
Default: false, Default: false,
}, },
"project": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
}, },
} }
} }
@ -148,6 +147,18 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
p.SetIpaddress(ipaddres.(string)) p.SetIpaddress(ipaddres.(string))
} }
// If there is a project supplied, we retreive and set the project id
if project, ok := d.GetOk("project"); ok {
// Retrieve the project UUID
projectid, e := retrieveUUID(cs, "project", project.(string))
if e != nil {
return e.Error()
}
// Set the default project ID
p.SetProjectid(projectid)
}
// If a keypair is supplied, add it to the parameter struct
if keypair, ok := d.GetOk("keypair"); ok { if keypair, ok := d.GetOk("keypair"); ok {
p.SetKeypair(keypair.(string)) p.SetKeypair(keypair.(string))
} }
@ -164,16 +175,6 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
p.SetUserdata(ud) p.SetUserdata(ud)
} }
// If project contains any info, we retreive the project id
if project, ok := d.GetOk("project"); ok {
projectid, e := retrieveUUID(cs, "project", project.(string))
if e != nil {
return e.Error()
}
log.Printf("[DEBUG] project id %s", projectid)
p.SetProjectid(projectid)
}
// Create the new instance // Create the new instance
r, err := cs.VirtualMachine.DeployVirtualMachine(p) r, err := cs.VirtualMachine.DeployVirtualMachine(p)
if err != nil { if err != nil {
@ -218,7 +219,7 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
setValueOrUUID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid) setValueOrUUID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
setValueOrUUID(d, "template", vm.Templatename, vm.Templateid) setValueOrUUID(d, "template", vm.Templatename, vm.Templateid)
setValueOrUUID(d, "project", vm.Project, vm.Projectid) setValueOrUUID(d, "project", vm.Project, vm.Projectid)
return nil return nil
} }

View File

@ -24,13 +24,7 @@ func TestAccCloudStackInstance_basic(t *testing.T) {
"cloudstack_instance.foobar", &instance), "cloudstack_instance.foobar", &instance),
testAccCheckCloudStackInstanceAttributes(&instance), testAccCheckCloudStackInstanceAttributes(&instance),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"cloudstack_instance.foobar", "cloudstack_instance.foobar", "user_data", "0cf3dcdc356ec8369494cb3991985ecd5296cdd5"),
"user_data",
"0cf3dcdc356ec8369494cb3991985ecd5296cdd5"),
resource.TestCheckResourceAttr(
"cloudstack_instance.foobar",
"keypair",
CLOUDSTACK_SSH_KEYPAIR),
), ),
}, },
}, },
@ -52,13 +46,7 @@ func TestAccCloudStackInstance_update(t *testing.T) {
"cloudstack_instance.foobar", &instance), "cloudstack_instance.foobar", &instance),
testAccCheckCloudStackInstanceAttributes(&instance), testAccCheckCloudStackInstanceAttributes(&instance),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"cloudstack_instance.foobar", "cloudstack_instance.foobar", "user_data", "0cf3dcdc356ec8369494cb3991985ecd5296cdd5"),
"user_data",
"0cf3dcdc356ec8369494cb3991985ecd5296cdd5"),
resource.TestCheckResourceAttr(
"cloudstack_instance.foobar",
"keypair",
CLOUDSTACK_SSH_KEYPAIR),
), ),
}, },
@ -99,7 +87,7 @@ func TestAccCloudStackInstance_fixedIP(t *testing.T) {
}) })
} }
func TestAccCloudStackInstance_Projectname(t *testing.T) { func TestAccCloudStackInstance_keyPair(t *testing.T) {
var instance cloudstack.VirtualMachine var instance cloudstack.VirtualMachine
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
@ -108,19 +96,19 @@ func TestAccCloudStackInstance_Projectname(t *testing.T) {
CheckDestroy: testAccCheckCloudStackInstanceDestroy, CheckDestroy: testAccCheckCloudStackInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCloudStackInstance_projectname, Config: testAccCloudStackInstance_keyPair,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackInstanceExists( testAccCheckCloudStackInstanceExists(
"cloudstack_instance.foobar", &instance), "cloudstack_instance.foobar", &instance),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"cloudstack_instance.foobar", "project", CLOUDSTACK_PROJECT_NAME), "cloudstack_instance.foobar", "keypair", "terraform-test-keypair"),
), ),
}, },
}, },
}) })
} }
func TestAccCloudStackInstance_Projectid(t *testing.T) { func TestAccCloudStackInstance_project(t *testing.T) {
var instance cloudstack.VirtualMachine var instance cloudstack.VirtualMachine
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
@ -129,12 +117,12 @@ func TestAccCloudStackInstance_Projectid(t *testing.T) {
CheckDestroy: testAccCheckCloudStackInstanceDestroy, CheckDestroy: testAccCheckCloudStackInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCloudStackInstance_projectid, Config: testAccCloudStackInstance_project,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackInstanceExists( testAccCheckCloudStackInstanceExists(
"cloudstack_instance.foobar", &instance), "cloudstack_instance.foobar", &instance),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"cloudstack_instance.foobar", "project", CLOUDSTACK_PROJECT_ID), "cloudstack_instance.foobar", "project", CLOUDSTACK_PROJECT_NAME),
), ),
}, },
}, },
@ -226,13 +214,9 @@ func testAccCheckCloudStackInstanceDestroy(s *terraform.State) error {
return fmt.Errorf("No instance ID is set") return fmt.Errorf("No instance ID is set")
} }
p := cs.VirtualMachine.NewDestroyVirtualMachineParams(rs.Primary.ID) _, _, err := cs.VirtualMachine.GetVirtualMachineByID(rs.Primary.ID)
_, err := cs.VirtualMachine.DestroyVirtualMachine(p) if err == nil {
return fmt.Errorf("Virtual Machine %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting instance (%s): %s",
rs.Primary.ID, err)
} }
} }
@ -247,15 +231,13 @@ resource "cloudstack_instance" "foobar" {
network = "%s" network = "%s"
template = "%s" template = "%s"
zone = "%s" zone = "%s"
keypair = "%s"
user_data = "foobar\nfoo\nbar" user_data = "foobar\nfoo\nbar"
expunge = true expunge = true
}`, }`,
CLOUDSTACK_SERVICE_OFFERING_1, CLOUDSTACK_SERVICE_OFFERING_1,
CLOUDSTACK_NETWORK_1, CLOUDSTACK_NETWORK_1,
CLOUDSTACK_TEMPLATE, CLOUDSTACK_TEMPLATE,
CLOUDSTACK_ZONE, CLOUDSTACK_ZONE)
CLOUDSTACK_SSH_KEYPAIR)
var testAccCloudStackInstance_renameAndResize = fmt.Sprintf(` var testAccCloudStackInstance_renameAndResize = fmt.Sprintf(`
resource "cloudstack_instance" "foobar" { resource "cloudstack_instance" "foobar" {
@ -265,15 +247,13 @@ resource "cloudstack_instance" "foobar" {
network = "%s" network = "%s"
template = "%s" template = "%s"
zone = "%s" zone = "%s"
keypair = "%s"
user_data = "foobar\nfoo\nbar" user_data = "foobar\nfoo\nbar"
expunge = true expunge = true
}`, }`,
CLOUDSTACK_SERVICE_OFFERING_2, CLOUDSTACK_SERVICE_OFFERING_2,
CLOUDSTACK_NETWORK_1, CLOUDSTACK_NETWORK_1,
CLOUDSTACK_TEMPLATE, CLOUDSTACK_TEMPLATE,
CLOUDSTACK_ZONE, CLOUDSTACK_ZONE)
CLOUDSTACK_SSH_KEYPAIR)
var testAccCloudStackInstance_fixedIP = fmt.Sprintf(` var testAccCloudStackInstance_fixedIP = fmt.Sprintf(`
resource "cloudstack_instance" "foobar" { resource "cloudstack_instance" "foobar" {
@ -291,38 +271,42 @@ resource "cloudstack_instance" "foobar" {
CLOUDSTACK_NETWORK_1_IPADDRESS, CLOUDSTACK_NETWORK_1_IPADDRESS,
CLOUDSTACK_TEMPLATE, CLOUDSTACK_TEMPLATE,
CLOUDSTACK_ZONE) CLOUDSTACK_ZONE)
var testAccCloudStackInstance_projectname = fmt.Sprintf(` var testAccCloudStackInstance_keyPair = fmt.Sprintf(`
resource "cloudstack_ssh_keypair" "foo" {
name = "terraform-test-keypair"
}
resource "cloudstack_instance" "foobar" { resource "cloudstack_instance" "foobar" {
name = "terraform-test" name = "terraform-test"
display_name = "terraform" display_name = "terraform"
service_offering= "%s" service_offering= "%s"
network = "%s" network = "%s"
ipaddress = "%s"
template = "%s" template = "%s"
zone = "%s" zone = "%s"
keypair = "${cloudstack_ssh_keypair.foo.name}"
expunge = true expunge = true
project = "%s"
}`, }`,
CLOUDSTACK_SERVICE_OFFERING_1, CLOUDSTACK_SERVICE_OFFERING_1,
CLOUDSTACK_NETWORK_1, CLOUDSTACK_NETWORK_1,
CLOUDSTACK_NETWORK_1_IPADDRESS,
CLOUDSTACK_TEMPLATE, CLOUDSTACK_TEMPLATE,
CLOUDSTACK_ZONE, CLOUDSTACK_ZONE)
CLOUDSTACK_PROJECT_NAME)
var testAccCloudStackInstance_projectid = fmt.Sprintf(` var testAccCloudStackInstance_project = fmt.Sprintf(`
resource "cloudstack_instance" "foobar" { resource "cloudstack_instance" "foobar" {
name = "terraform-test" name = "terraform-test"
display_name = "terraform" display_name = "terraform"
service_offering= "%s" service_offering= "%s"
network = "%s" network = "%s"
template = "%s" template = "%s"
project = "%s"
zone = "%s" zone = "%s"
expunge = true expunge = true
project = "%s"
}`, }`,
CLOUDSTACK_SERVICE_OFFERING_1, CLOUDSTACK_SERVICE_OFFERING_1,
CLOUDSTACK_NETWORK_1, CLOUDSTACK_PROJECT_NETWORK,
CLOUDSTACK_TEMPLATE, CLOUDSTACK_TEMPLATE,
CLOUDSTACK_ZONE, CLOUDSTACK_PROJECT_NAME,
CLOUDSTACK_PROJECT_ID) CLOUDSTACK_ZONE)

View File

@ -136,7 +136,7 @@ func resourceCloudStackIPAddressDelete(d *schema.ResourceData, meta interface{})
return nil return nil
} }
return fmt.Errorf("Error deleting network ACL list %s: %s", d.Get("name").(string), err) return fmt.Errorf("Error disassociating IP address %s: %s", d.Get("name").(string), err)
} }
return nil return nil

View File

@ -103,13 +103,9 @@ func testAccCheckCloudStackIPAddressDestroy(s *terraform.State) error {
return fmt.Errorf("No IP address ID is set") return fmt.Errorf("No IP address ID is set")
} }
p := cs.Address.NewDisassociateIpAddressParams(rs.Primary.ID) ip, _, err := cs.Address.GetPublicIpAddressByID(rs.Primary.ID)
_, err := cs.Address.DisassociateIpAddress(p) if err == nil && ip.Associatednetworkid != "" {
return fmt.Errorf("Public IP %s still associated", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error disassociating IP address (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -160,11 +160,9 @@ func testAccCheckCloudStackNetworkACLRuleDestroy(s *terraform.State) error {
continue continue
} }
p := cs.NetworkACL.NewDeleteNetworkACLParams(uuid) _, _, err := cs.NetworkACL.GetNetworkACLByID(uuid)
_, err := cs.NetworkACL.DeleteNetworkACL(p) if err == nil {
return fmt.Errorf("Network ACL rule %s still exists", rs.Primary.ID)
if err != nil {
return err
} }
} }
} }

View File

@ -86,13 +86,9 @@ func testAccCheckCloudStackNetworkACLDestroy(s *terraform.State) error {
return fmt.Errorf("No network ACL ID is set") return fmt.Errorf("No network ACL ID is set")
} }
p := cs.NetworkACL.NewDeleteNetworkACLListParams(rs.Primary.ID) _, _, err := cs.NetworkACL.GetNetworkACLListByID(rs.Primary.ID)
_, err := cs.NetworkACL.DeleteNetworkACLList(p) if err == nil {
return fmt.Errorf("Network ACl list %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting network ACL (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -140,13 +140,9 @@ func testAccCheckCloudStackNetworkDestroy(s *terraform.State) error {
return fmt.Errorf("No network ID is set") return fmt.Errorf("No network ID is set")
} }
p := cs.Network.NewDeleteNetworkParams(rs.Primary.ID) _, _, err := cs.Network.GetNetworkByID(rs.Primary.ID)
_, err := cs.Network.DeleteNetwork(p) if err == nil {
return fmt.Errorf("Network %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting network (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -140,13 +140,9 @@ func testAccCheckCloudStackNICDestroy(s *terraform.State) error {
return fmt.Errorf("No instance ID is set") return fmt.Errorf("No instance ID is set")
} }
p := cs.VirtualMachine.NewDestroyVirtualMachineParams(rs.Primary.ID) _, _, err := cs.VirtualMachine.GetVirtualMachineByID(rs.Primary.ID)
_, err := cs.VirtualMachine.DestroyVirtualMachine(p) if err == nil {
return fmt.Errorf("Virtual Machine %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting instance (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -140,11 +140,9 @@ func testAccCheckCloudStackPortForwardDestroy(s *terraform.State) error {
continue continue
} }
p := cs.Firewall.NewDeletePortForwardingRuleParams(uuid) _, _, err := cs.Firewall.GetPortForwardingRuleByID(uuid)
_, err := cs.Firewall.DeletePortForwardingRule(p) if err == nil {
return fmt.Errorf("Port forward %s still exists", rs.Primary.ID)
if err != nil {
return err
} }
} }
} }

View File

@ -2,10 +2,12 @@ package cloudstack
import ( import (
"fmt" "fmt"
"io/ioutil"
"log" "log"
"strings" "strings"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/mitchellh/go-homedir"
"github.com/xanzy/go-cloudstack/cloudstack" "github.com/xanzy/go-cloudstack/cloudstack"
) )
@ -48,54 +50,59 @@ func resourceCloudStackSSHKeyPairCreate(d *schema.ResourceData, meta interface{}
publicKey := d.Get("public_key").(string) publicKey := d.Get("public_key").(string)
if publicKey != "" { if publicKey != "" {
//register key supplied // Register supplied key
p := cs.SSH.NewRegisterSSHKeyPairParams(name, publicKey) keyPath, err := homedir.Expand(publicKey)
r, err := cs.SSH.RegisterSSHKeyPair(p) if err != nil {
return fmt.Errorf("Error expanding the public key path: %v", err)
}
key, err := ioutil.ReadFile(keyPath)
if err != nil {
return fmt.Errorf("Error reading the public key: %v", err)
}
p := cs.SSH.NewRegisterSSHKeyPairParams(name, string(key))
_, err = cs.SSH.RegisterSSHKeyPair(p)
if err != nil { if err != nil {
return err return err
} }
log.Printf("[DEBUG] RegisterSSHKeyPair response: %+v\n", r)
log.Printf("[DEBUG] Key pair successfully registered at Cloudstack")
d.SetId(name)
} else { } else {
//no key supplied, must create one and return the private key // No key supplied, must create one and return the private key
p := cs.SSH.NewCreateSSHKeyPairParams(name) p := cs.SSH.NewCreateSSHKeyPairParams(name)
r, err := cs.SSH.CreateSSHKeyPair(p) r, err := cs.SSH.CreateSSHKeyPair(p)
if err != nil { if err != nil {
return err return err
} }
log.Printf("[DEBUG] CreateSSHKeyPair response: %+v\n", r)
log.Printf("[DEBUG] Key pair successfully generated at Cloudstack")
log.Printf("[DEBUG] Private key returned: %s", r.Privatekey)
d.Set("private_key", r.Privatekey) d.Set("private_key", r.Privatekey)
d.SetId(name)
} }
log.Printf("[DEBUG] Key pair successfully generated at Cloudstack")
d.SetId(name)
return resourceCloudStackSSHKeyPairRead(d, meta) return resourceCloudStackSSHKeyPairRead(d, meta)
} }
func resourceCloudStackSSHKeyPairRead(d *schema.ResourceData, meta interface{}) error { func resourceCloudStackSSHKeyPairRead(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
log.Printf("[DEBUG] looking for ssh key %s with name %s", d.Id(), d.Get("name").(string)) log.Printf("[DEBUG] looking for key pair with name %s", d.Id())
p := cs.SSH.NewListSSHKeyPairsParams() p := cs.SSH.NewListSSHKeyPairsParams()
p.SetName(d.Get("name").(string)) p.SetName(d.Id())
r, err := cs.SSH.ListSSHKeyPairs(p) r, err := cs.SSH.ListSSHKeyPairs(p)
if err != nil { if err != nil {
return err return err
} }
if r.Count == 0 { if r.Count == 0 {
log.Printf("[DEBUG] Key pair %s does not exist", d.Get("name").(string)) log.Printf("[DEBUG] Key pair %s does not exist", d.Id())
d.Set("name", "") d.SetId("")
return nil return nil
} }
//SSHKeyPair name is unique in a cloudstack account so dont need to check for multiple //SSHKeyPair name is unique in a cloudstack account so dont need to check for multiple
d.Set("name", r.SSHKeyPairs[0].Name) d.Set("name", r.SSHKeyPairs[0].Name)
d.Set("fingerprint", r.SSHKeyPairs[0].Fingerprint) d.Set("fingerprint", r.SSHKeyPairs[0].Fingerprint)
log.Printf("[DEBUG] Read ssh key pair %+v\n", d)
return nil return nil
} }
@ -104,18 +111,18 @@ func resourceCloudStackSSHKeyPairDelete(d *schema.ResourceData, meta interface{}
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
// Create a new parameter struct // Create a new parameter struct
p := cs.SSH.NewDeleteSSHKeyPairParams(d.Get("name").(string)) p := cs.SSH.NewDeleteSSHKeyPairParams(d.Id())
// Remove the SSH Keypair // Remove the SSH Keypair
_, err := cs.SSH.DeleteSSHKeyPair(p) _, err := cs.SSH.DeleteSSHKeyPair(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the UUID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"A key pair with name '%s' does not exist for account", d.Get("name").(string))) { "A key pair with name '%s' does not exist for account", d.Id())) {
return nil return nil
} }
return fmt.Errorf("Error deleting SSH Keypair: %s", err) return fmt.Errorf("Error deleting key pair: %s", err)
} }
return nil return nil

View File

@ -2,7 +2,6 @@ package cloudstack
import ( import (
"fmt" "fmt"
"log"
"strings" "strings"
"testing" "testing"
@ -24,7 +23,7 @@ func TestAccCloudStackSSHKeyPair_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStackSSHKeyPairExists("cloudstack_ssh_keypair.foo", &sshkey), testAccCheckCloudStackSSHKeyPairExists("cloudstack_ssh_keypair.foo", &sshkey),
testAccCheckCloudStackSSHKeyPairAttributes(&sshkey), testAccCheckCloudStackSSHKeyPairAttributes(&sshkey),
testAccCheckCloudStackSSHKeyPairCreateAttributes("cloudstack_ssh_keypair.foo"), testAccCheckCloudStackSSHKeyPairCreateAttributes("terraform-test-keypair"),
), ),
}, },
}, },
@ -61,64 +60,69 @@ func testAccCheckCloudStackSSHKeyPairExists(n string, sshkey *cloudstack.SSHKeyP
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.Primary.Attributes["name"] == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No ssh key name is set") return fmt.Errorf("No key pair ID is set")
} }
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient) cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
p := cs.SSH.NewListSSHKeyPairsParams() p := cs.SSH.NewListSSHKeyPairsParams()
p.SetName(rs.Primary.Attributes["name"]) p.SetName(rs.Primary.ID)
list, err := cs.SSH.ListSSHKeyPairs(p)
list, err := cs.SSH.ListSSHKeyPairs(p)
if err != nil { if err != nil {
return err return err
} }
if list.Count == 1 && list.SSHKeyPairs[0].Name == rs.Primary.Attributes["name"] { if list.Count != 1 || list.SSHKeyPairs[0].Name != rs.Primary.ID {
//ssh key exists return fmt.Errorf("Key pair not found")
*sshkey = *list.SSHKeyPairs[0]
return nil
} }
return fmt.Errorf("SSH key not found") *sshkey = *list.SSHKeyPairs[0]
return nil
} }
} }
func testAccCheckCloudStackSSHKeyPairAttributes( func testAccCheckCloudStackSSHKeyPairAttributes(
sshkey *cloudstack.SSHKeyPair) resource.TestCheckFunc { keypair *cloudstack.SSHKeyPair) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
fingerprintLen := len(sshkey.Fingerprint) fpLen := len(keypair.Fingerprint)
if fingerprintLen != 47 { if fpLen != 47 {
return fmt.Errorf( return fmt.Errorf("SSH key: Attribute private_key expected length 47, got %d", fpLen)
"SSH key: Attribute private_key expected length 47, got %d",
fingerprintLen)
} }
return nil return nil
} }
} }
func testAccCheckCloudStackSSHKeyPairCreateAttributes( func testAccCheckCloudStackSSHKeyPairCreateAttributes(name string) resource.TestCheckFunc {
name string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
ms := s.RootModule() found := false
rs, ok := ms.Resources[name]
if !ok { for _, rs := range s.RootModule().Resources {
return fmt.Errorf("Not found: %s", name) if rs.Type != "cloudstack_ssh_keypair" {
continue
}
if rs.Primary.ID != name {
continue
}
if !strings.Contains(rs.Primary.Attributes["private_key"], "PRIVATE KEY") {
return fmt.Errorf(
"SSH key: Attribute private_key expected 'PRIVATE KEY' to be present, got %s",
rs.Primary.Attributes["private_key"])
}
found = true
break
} }
is := rs.Primary if !found {
if is == nil { return fmt.Errorf("Could not find key pair %s", name)
return fmt.Errorf("No primary instance: %s", name)
} }
log.Printf("Private key calculated: %s", is.Attributes["private_key"])
if !strings.Contains(is.Attributes["private_key"], "PRIVATE KEY") {
return fmt.Errorf(
"SSH key: Attribute private_key expected 'PRIVATE KEY' to be present, got %s",
is.Attributes["private_key"])
}
return nil return nil
} }
} }
@ -131,17 +135,23 @@ func testAccCheckCloudStackSSHKeyPairDestroy(s *terraform.State) error {
continue continue
} }
if rs.Primary.Attributes["name"] == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No ssh key name is set") return fmt.Errorf("No key pair ID is set")
} }
p := cs.SSH.NewDeleteSSHKeyPairParams(rs.Primary.Attributes["name"]) p := cs.SSH.NewListSSHKeyPairsParams()
_, err := cs.SSH.DeleteSSHKeyPair(p) p.SetName(rs.Primary.ID)
list, err := cs.SSH.ListSSHKeyPairs(p)
if err != nil { if err != nil {
return fmt.Errorf( return err
"Error deleting ssh key (%s): %s", }
rs.Primary.Attributes["name"], err) if list.Count != 1 {
return fmt.Errorf("Found more Key pair %s still exists", rs.Primary.ID)
}
if list.SSHKeyPairs[0].Name == rs.Primary.ID {
return fmt.Errorf("Key pair %s still exists", rs.Primary.ID)
} }
} }
@ -150,11 +160,11 @@ func testAccCheckCloudStackSSHKeyPairDestroy(s *terraform.State) error {
var testAccCloudStackSSHKeyPair_create = fmt.Sprintf(` var testAccCloudStackSSHKeyPair_create = fmt.Sprintf(`
resource "cloudstack_ssh_keypair" "foo" { resource "cloudstack_ssh_keypair" "foo" {
name = "terraform-testacc" name = "terraform-test-keypair"
}`) }`)
var testAccCloudStackSSHKeyPair_register = fmt.Sprintf(` var testAccCloudStackSSHKeyPair_register = fmt.Sprintf(`
resource "cloudstack_ssh_keypair" "foo" { resource "cloudstack_ssh_keypair" "foo" {
name = "terraform-testacc" name = "terraform-test-keypair"
public_key = "%s" public_key = "%s"
}`, CLOUDSTACK_SSH_PUBLIC_KEY) }`, CLOUDSTACK_SSH_PUBLIC_KEY)

View File

@ -149,13 +149,9 @@ func testAccCheckCloudStackTemplateDestroy(s *terraform.State) error {
return fmt.Errorf("No template ID is set") return fmt.Errorf("No template ID is set")
} }
p := cs.Template.NewDeleteTemplateParams(rs.Primary.ID) _, _, err := cs.Template.GetTemplateByID(rs.Primary.ID, "executable")
_, err := cs.Template.DeleteTemplate(p) if err == nil {
return fmt.Errorf("Template %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting template (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -92,13 +92,9 @@ func testAccCheckCloudStackVPCDestroy(s *terraform.State) error {
return fmt.Errorf("No VPC ID is set") return fmt.Errorf("No VPC ID is set")
} }
p := cs.VPC.NewDeleteVPCParams(rs.Primary.ID) _, _, err := cs.VPC.GetVPCByID(rs.Primary.ID)
_, err := cs.VPC.DeleteVPC(p) if err == nil {
return fmt.Errorf("VPC %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting VPC (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -71,13 +71,9 @@ func testAccCheckCloudStackVPNConnectionDestroy(s *terraform.State) error {
return fmt.Errorf("No VPN Connection ID is set") return fmt.Errorf("No VPN Connection ID is set")
} }
p := cs.VPN.NewDeleteVpnConnectionParams(rs.Primary.ID) _, _, err := cs.VPN.GetVpnConnectionByID(rs.Primary.ID)
_, err := cs.VPN.DeleteVpnConnection(p) if err == nil {
return fmt.Errorf("VPN Connection %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting VPN Connection (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -163,13 +163,9 @@ func testAccCheckCloudStackVPNCustomerGatewayDestroy(s *terraform.State) error {
return fmt.Errorf("No VPN Customer Gateway ID is set") return fmt.Errorf("No VPN Customer Gateway ID is set")
} }
p := cs.VPN.NewDeleteVpnCustomerGatewayParams(rs.Primary.ID) _, _, err := cs.VPN.GetVpnCustomerGatewayByID(rs.Primary.ID)
_, err := cs.VPN.DeleteVpnCustomerGateway(p) if err == nil {
return fmt.Errorf("VPN Customer Gateway %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting VPN Customer Gateway (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -71,13 +71,9 @@ func testAccCheckCloudStackVPNGatewayDestroy(s *terraform.State) error {
return fmt.Errorf("No VPN Gateway ID is set") return fmt.Errorf("No VPN Gateway ID is set")
} }
p := cs.VPN.NewDeleteVpnGatewayParams(rs.Primary.ID) _, _, err := cs.VPN.GetVpnGatewayByID(rs.Primary.ID)
_, err := cs.VPN.DeleteVpnGateway(p) if err == nil {
return fmt.Errorf("VPN Gateway %s still exists", rs.Primary.ID)
if err != nil {
return fmt.Errorf(
"Error deleting VPN Gateway (%s): %s",
rs.Primary.ID, err)
} }
} }

View File

@ -32,23 +32,29 @@ The following arguments are supported:
* `display_name` - (Optional) The display name of the instance. * `display_name` - (Optional) The display name of the instance.
* `service_offering` - (Required) The name or ID of the service offering used for this instance. * `service_offering` - (Required) The name or ID of the service offering used
for this instance.
* `network` - (Optional) The name or ID of the network to connect this instance to. * `network` - (Optional) The name or ID of the network to connect this instance
Changing this forces a new resource to be created. to. Changing this forces a new resource to be created.
* `ipaddress` - (Optional) The IP address to assign to this instance. Changing * `ipaddress` - (Optional) The IP address to assign to this instance. Changing
this forces a new resource to be created. this forces a new resource to be created.
* `template` - (Required) The name or ID of the template used for this instance. * `template` - (Required) The name or ID of the template used for this
Changing this forces a new resource to be created. instance. Changing this forces a new resource to be created.
* `project` - (Optional) The name or ID of the project to deploy this
instance to. Changing this forces a new resource to be created.
* `zone` - (Required) The name of the zone where this instance will be created. * `zone` - (Required) The name of the zone where this instance will be created.
Changing this forces a new resource to be created. Changing this forces a new resource to be created.
* `user_data` - (Optional) The user data to provide when launching the instance. * `user_data` - (Optional) The user data to provide when launching the
instance.
* `keypair` - (Optional) The name of the SSH keypair that will be used to access this instance. * `keypair` - (Optional) The name of the SSH key pair that will be used to
access this instance.
* `expunge` - (Optional) This determines if the instance is expunged when it is * `expunge` - (Optional) This determines if the instance is expunged when it is
destroyed (defaults false) destroyed (defaults false)

View File

@ -3,17 +3,17 @@ layout: "cloudstack"
page_title: "CloudStack: cloudstack_ssh_keypair" page_title: "CloudStack: cloudstack_ssh_keypair"
sidebar_current: "docs-cloudstack-resource-ssh-keypair" sidebar_current: "docs-cloudstack-resource-ssh-keypair"
description: |- description: |-
Creates or registers an SSH keypair. Creates or registers an SSH key pair.
--- ---
# cloudstack\_ssh\_keypair # cloudstack\_ssh\_keypair
Creates or registers an SSH keypair. Creates or registers an SSH key pair.
## Example Usage ## Example Usage
``` ```
resource "cloudstack_ssh_keypair" "myKey" { resource "cloudstack_ssh_keypair" "default" {
name = "myKey" name = "myKey"
} }
``` ```
@ -22,15 +22,19 @@ resource "cloudstack_ssh_keypair" "myKey" {
The following arguments are supported: The following arguments are supported:
* `name` - (Required) The name to give the SSH keypair. This is a unique value within a Cloudstack account. * `name` - (Required) The name of the SSH key pair. This is a unique value
within a CloudStack account. Changing this forces a new resource to be
created.
* `public_key` - (Optional) The full public key text of this keypair. If this is omitted, Cloudstack * `public_key` - (Optional) The path to a public key that will be uploaded
will generate a new keypair. the remote machine. If this is omitted, CloudStack will generate a new
key pair. Changing this forces a new resource to be created.
## Attributes Reference ## Attributes Reference
The following attributes are exported: The following attributes are exported:
* `id` - The keypair ID. This is set to the keypair `name` argument. * `id` - The key pair ID.
* `fingerprint` - The fingerprint of the public key specified or calculated. * `fingerprint` - The fingerprint of the public key specified or created.
* `private_key` - This is returned only if Cloudstack generated the keypair. * `private_key` - The private key generated by CloudStack. Only available
if CloudStack generated the key pair.