From 1c8e4c81e494e97366e735f6ca10626b38709500 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 3 Dec 2015 10:51:59 +0000 Subject: [PATCH] provider/docker: Inline ports and volumes schemas for consistency --- resource_docker_container.go | 122 ++++++++++++++++------------------- 1 file changed, 57 insertions(+), 65 deletions(-) diff --git a/resource_docker_container.go b/resource_docker_container.go index 6ad5176a..76b3e153 100644 --- a/resource_docker_container.go +++ b/resource_docker_container.go @@ -118,16 +118,69 @@ func resourceDockerContainer() *schema.Resource { Type: schema.TypeSet, Optional: true, ForceNew: true, - Elem: getVolumesElem(), - Set: resourceDockerVolumesHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "from_container": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "container_path": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "host_path": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "read_only": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + }, + }, + Set: resourceDockerVolumesHash, }, "ports": &schema.Schema{ Type: schema.TypeSet, Optional: true, ForceNew: true, - Elem: getPortsElem(), - Set: resourceDockerPortsHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "internal": &schema.Schema{ + Type: schema.TypeInt, + Required: true, + ForceNew: true, + }, + + "external": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "ip": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "protocol": &schema.Schema{ + Type: schema.TypeString, + Default: "tcp", + Optional: true, + ForceNew: true, + }, + }, + }, + Set: resourceDockerPortsHash, }, "hosts": &schema.Schema{ @@ -263,67 +316,6 @@ func resourceDockerContainer() *schema.Resource { } } -func getVolumesElem() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "from_container": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - - "container_path": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - - "host_path": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - - "read_only": &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - }, - }, - } -} - -func getPortsElem() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "internal": &schema.Schema{ - Type: schema.TypeInt, - Required: true, - ForceNew: true, - }, - - "external": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - }, - - "ip": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - - "protocol": &schema.Schema{ - Type: schema.TypeString, - Default: "tcp", - Optional: true, - ForceNew: true, - }, - }, - } -} - func resourceDockerPortsHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{})