Merge pull request #8 from jtopjian/group-resource
Add ansible_group resource
This commit is contained in:
Коммит
d89a9306a7
|
@ -20,6 +20,15 @@ resource "ansible_host" "example" {
|
|||
ansible_user = "admin"
|
||||
}
|
||||
}
|
||||
|
||||
resource "ansible_group" "web" {
|
||||
inventory_group_name = "web"
|
||||
children = ["foo", "bar", "baz"]
|
||||
vars {
|
||||
foo = "bar"
|
||||
bar = 2
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Alternatives and Similar Projects
|
||||
|
|
|
@ -8,7 +8,8 @@ import (
|
|||
func Provider() terraform.ResourceProvider {
|
||||
return &schema.Provider{
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"ansible_host": resourceHost(),
|
||||
"ansible_host": resourceHost(),
|
||||
"ansible_group": resourceGroup(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package ansible
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func resourceGroup() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceAnsibleInventoryGroupCreate,
|
||||
Read: schema.Noop,
|
||||
Update: schema.Noop,
|
||||
Delete: schema.Noop,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"inventory_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"children": {
|
||||
Type: schema.TypeList,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"vars": {
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceAnsibleInventoryGroupCreate(d *schema.ResourceData, _ interface{}) error {
|
||||
d.SetId(d.Get("inventory_group_name").(string))
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package ansible
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAnsibleGroup(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAnsibleGroupConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
"ansible_group.group_1", "id", "group_1"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"ansible_group.group_1", "children.0", "foo"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"ansible_group.group_1", "children.2", "baz"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"ansible_group.group_1", "vars.foo", "bar"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"ansible_group.group_1", "vars.bar", "2"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const testAnsibleGroupConfig = `
|
||||
resource "ansible_group" "group_1" {
|
||||
inventory_group_name = "group_1"
|
||||
children = ["foo", "bar", "baz"]
|
||||
vars {
|
||||
foo = "bar"
|
||||
bar = 2
|
||||
}
|
||||
}
|
||||
`
|
Загрузка…
Ссылка в новой задаче