1
1
mirror of https://github.com/adammck/terraform-inventory synced 2024-11-22 20:01:58 +01:00

Add CloudStack support

This commit is contained in:
Lars Tobias Skjong-Børsting 2015-06-23 19:39:56 +02:00
parent ffb3ce1fdf
commit c5e5e40cd7
6 changed files with 60 additions and 2 deletions

@ -2,6 +2,9 @@ variable "do_token" {}
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "aws_subnet_id" {}
variable "cs_api_url" {}
variable "cs_api_key" {}
variable "cs_secret_key" {}
provider "aws" {
access_key = "${var.aws_access_key}"
@ -13,6 +16,13 @@ provider "digitalocean" {
token = "${var.do_token}"
}
provider "cloudstack" {
api_url = "${var.cs_api_url}"
api_key = "${var.cs_api_key}"
secret_key = "${var.cs_secret_key}"
}
resource "aws_instance" "web-aws" {
ami = "ami-96a818fe"
instance_type = "t2.micro"
@ -31,3 +41,10 @@ resource "digitalocean_droplet" "web-do" {
size = "512mb"
ssh_keys = [862272]
}
resource "cloudstack_instance" "web-cs" {
name = "terraform-inventory-2"
service_offering = "small"
template = "centos-7-0-x64"
zone = "nyc2"
}

@ -60,6 +60,20 @@
"status": "active"
}
}
},
"cloudstack_instance.web-cs": {
"type": "cloudstack_instance",
"primary": {
"id": "500fb40e-8796-a724-8bcd-211bd1866bc0",
"attributes": {
"id": "500fb40e-8796-a724-8bcd-211bd1866bc0",
"ipaddress": "10.2.1.5",
"name": "terraform-inventory-2",
"service_offering": "small",
"template": "centos-7-0-x64",
"zone": "nyc2"
}
}
}
}
}

@ -1,5 +1,6 @@
- hosts:
- web-aws
- web-do
- web-cs
tasks:
- command: "echo Hello, world!"

@ -2,3 +2,6 @@ do_token = ""
aws_access_key = ""
aws_secret_key = ""
aws_subnet_id = ""
cs_api_url = ""
cs_api_key = ""
cs_secret_key = ""

@ -21,6 +21,7 @@ func init() {
"ipv4_address", // DO
"public_ip", // AWS
"private_ip", // AWS
"ipaddress", // CS
}
}

@ -57,6 +57,16 @@ const exampleStateFile = `
"ipv4_address": "192.168.0.3"
}
}
},
"cloudstack_instance.four": {
"type": "cloudstack_instance",
"primary": {
"id": "aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"attributes": {
"id": "aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"ipaddress": "10.2.1.5"
}
}
}
}
}
@ -80,10 +90,11 @@ func TestResources(t *testing.T) {
assert.Nil(t, err)
inst := s.resources()
assert.Equal(t, 3, len(inst))
assert.Equal(t, 4, len(inst))
assert.Equal(t, "aws_instance", inst["one"].Type)
assert.Equal(t, "aws_instance", inst["two"].Type)
assert.Equal(t, "digitalocean_droplet", inst["three"].Type)
assert.Equal(t, "cloudstack_instance", inst["four"].Type)
}
func TestAddress(t *testing.T) {
@ -94,10 +105,11 @@ func TestAddress(t *testing.T) {
assert.Nil(t, err)
inst := s.resources()
assert.Equal(t, 3, len(inst))
assert.Equal(t, 4, len(inst))
assert.Equal(t, "10.0.0.1", inst["one"].Address())
assert.Equal(t, "50.0.0.1", inst["two"].Address())
assert.Equal(t, "192.168.0.3", inst["three"].Address())
assert.Equal(t, "10.2.1.5", inst["four"].Address())
}
func TestIsSupported(t *testing.T) {
@ -125,4 +137,14 @@ func TestIsSupported(t *testing.T) {
},
}
assert.Equal(t, true, r.isSupported())
r = resourceState{
Type: "cloudstack_instance",
Primary: instanceState{
Attributes: map[string]string{
"ipaddress": "10.2.1.5",
},
},
}
assert.Equal(t, true, r.isSupported())
}