mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-20 22:59:42 -05:00
style: format with gofumpt
https://github.com/mvdan/gofumpt ``` $ gofumpt -l -s -w docker/* ```
This commit is contained in:
parent
cf34e9e1b1
commit
f213e3a348
30 changed files with 149 additions and 161 deletions
|
|
@ -13,55 +13,55 @@ func dataSourceDockerNetwork() *schema.Resource {
|
|||
Read: dataSourceDockerNetworkRead,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"id": &schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"driver": &schema.Schema{
|
||||
"driver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"options": &schema.Schema{
|
||||
"options": {
|
||||
Type: schema.TypeMap,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"internal": &schema.Schema{
|
||||
"internal": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"ipam_config": &schema.Schema{
|
||||
"ipam_config": {
|
||||
Type: schema.TypeSet,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"subnet": &schema.Schema{
|
||||
"subnet": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"ip_range": &schema.Schema{
|
||||
"ip_range": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"gateway": &schema.Schema{
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"aux_address": &schema.Schema{
|
||||
"aux_address": {
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
|
@ -70,7 +70,7 @@ func dataSourceDockerNetwork() *schema.Resource {
|
|||
},
|
||||
},
|
||||
|
||||
"scope": &schema.Schema{
|
||||
"scope": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
|
@ -81,7 +81,6 @@ func dataSourceDockerNetwork() *schema.Resource {
|
|||
type ipamMap map[string]interface{}
|
||||
|
||||
func dataSourceDockerNetworkRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
name, nameOk := d.GetOk("name")
|
||||
_, idOk := d.GetOk("id")
|
||||
|
||||
|
|
@ -92,7 +91,6 @@ func dataSourceDockerNetworkRead(d *schema.ResourceData, meta interface{}) error
|
|||
client := meta.(*ProviderConfig).DockerClient
|
||||
|
||||
network, err := client.NetworkInspect(context.Background(), name.(string), types.NetworkInspectOptions{})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not find docker network: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@ package docker
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
||||
)
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ func TestAccDockerNetworkDataSource_basic(t *testing.T) {
|
|||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
{
|
||||
Config: testAccDockerNetworkDataSourceConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("data.docker_network.bridge", "name", "bridge"),
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ func dataSourceDockerRegistryImageRead(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
digest, err := getImageDigest(pullOpts.Registry, pullOpts.Repository, pullOpts.Tag, username, password, false)
|
||||
|
||||
if err != nil {
|
||||
digest, err = getImageDigest(pullOpts.Registry, pullOpts.Repository, pullOpts.Tag, username, password, true)
|
||||
if err != nil {
|
||||
|
|
@ -116,7 +115,6 @@ func getImageDigest(registry, image, tag, username, password string, fallback bo
|
|||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error during registry request: %s", err)
|
||||
}
|
||||
|
|
@ -134,7 +132,6 @@ func getImageDigest(registry, image, tag, username, password string, fallback bo
|
|||
params.Set("service", auth["service"])
|
||||
params.Set("scope", auth["scope"])
|
||||
tokenRequest, err := http.NewRequest("GET", auth["realm"]+"?"+params.Encode(), nil)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error creating registry request: %s", err)
|
||||
}
|
||||
|
|
@ -144,7 +141,6 @@ func getImageDigest(registry, image, tag, username, password string, fallback bo
|
|||
}
|
||||
|
||||
tokenResponse, err := client.Do(tokenRequest)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error during registry request: %s", err)
|
||||
}
|
||||
|
|
@ -166,7 +162,6 @@ func getImageDigest(registry, image, tag, username, password string, fallback bo
|
|||
|
||||
req.Header.Set("Authorization", "Bearer "+token.Token)
|
||||
digestResponse, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error during registry request: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,12 +57,12 @@ func mapToLabelSet(labels map[string]string) *schema.Set {
|
|||
|
||||
var labelSchema = &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"label": &schema.Schema{
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Description: "Name of the label",
|
||||
Required: true,
|
||||
},
|
||||
"value": &schema.Schema{
|
||||
"value": {
|
||||
Type: schema.TypeString,
|
||||
Description: "Value of the label",
|
||||
Required: true,
|
||||
|
|
@ -70,11 +70,11 @@ var labelSchema = &schema.Resource{
|
|||
},
|
||||
}
|
||||
|
||||
//gatherImmediateSubkeys given an incomplete attribute identifier, find all
|
||||
//the strings (if any) that appear after this one in the various dot-separated
|
||||
//identifiers.
|
||||
// gatherImmediateSubkeys given an incomplete attribute identifier, find all
|
||||
// the strings (if any) that appear after this one in the various dot-separated
|
||||
// identifiers.
|
||||
func gatherImmediateSubkeys(attrs map[string]string, partialKey string) []string {
|
||||
var immediateSubkeys = []string{}
|
||||
immediateSubkeys := []string{}
|
||||
for k := range attrs {
|
||||
prefix := partialKey + "."
|
||||
if strings.HasPrefix(k, prefix) {
|
||||
|
|
@ -90,7 +90,7 @@ func gatherImmediateSubkeys(attrs map[string]string, partialKey string) []string
|
|||
func getLabelMapForPartialKey(attrs map[string]string, partialKey string) map[string]string {
|
||||
setIDs := gatherImmediateSubkeys(attrs, partialKey)
|
||||
|
||||
var labelMap = map[string]string{}
|
||||
labelMap := map[string]string{}
|
||||
for _, id := range setIDs {
|
||||
if id == "#" {
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func TestMigrateServiceLabelState_empty_labels(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
//first validate that we build that correctly
|
||||
// first validate that we build that correctly
|
||||
v0Config := terraform.NewResourceConfigRaw(v0State)
|
||||
warns, errs := resourceDockerServiceV0().Validate(v0Config)
|
||||
if len(warns) > 0 || len(errs) > 0 {
|
||||
|
|
@ -83,7 +83,7 @@ func TestMigrateServiceLabelState_with_labels(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
//first validate that we build that correctly
|
||||
// first validate that we build that correctly
|
||||
v0Config := terraform.NewResourceConfigRaw(v0State)
|
||||
warns, errs := resourceDockerServiceV0().Validate(v0Config)
|
||||
if len(warns) > 0 || len(errs) > 0 {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,10 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
||||
)
|
||||
|
||||
var testAccProviders map[string]terraform.ResourceProvider
|
||||
var testAccProvider *schema.Provider
|
||||
var (
|
||||
testAccProviders map[string]terraform.ResourceProvider
|
||||
testAccProvider *schema.Provider
|
||||
)
|
||||
|
||||
func init() {
|
||||
testAccProvider = Provider().(*schema.Provider)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"log"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
|
@ -62,7 +61,6 @@ func resourceDockerConfigCreate(d *schema.ResourceData, meta interface{}) error
|
|||
func resourceDockerConfigRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ProviderConfig).DockerClient
|
||||
config, _, err := client.ConfigInspectWithRaw(context.Background(), d.Id())
|
||||
|
||||
if err != nil {
|
||||
log.Printf("[WARN] Config (%s) not found, removing from state", d.Id())
|
||||
d.SetId("")
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"context"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
||||
)
|
||||
|
|
@ -35,6 +35,7 @@ func TestAccDockerConfig_basic(t *testing.T) {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccDockerConfig_basicUpdatable(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ func resourceDockerContainer() *schema.Resource {
|
|||
Version: 1,
|
||||
Type: resourceDockerContainerV1().CoreConfigSchema().ImpliedType(),
|
||||
Upgrade: func(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
|
||||
//TODO do the ohter V0-to-V1 migration, unless we're okay
|
||||
//with breaking for users who straggled on their docker
|
||||
//provider version
|
||||
// TODO do the ohter V0-to-V1 migration, unless we're okay
|
||||
// with breaking for users who straggled on their docker
|
||||
// provider version
|
||||
|
||||
return migrateContainerLabels(rawState), nil
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"archive/tar"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
|
@ -16,8 +17,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
|
|
@ -28,9 +27,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
creationTime time.Time
|
||||
)
|
||||
var creationTime time.Time
|
||||
|
||||
func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
var err error
|
||||
|
|
@ -431,9 +428,9 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
|
|||
buf := new(bytes.Buffer)
|
||||
tw := tar.NewWriter(buf)
|
||||
if executable {
|
||||
mode = 0744
|
||||
mode = 0o744
|
||||
} else {
|
||||
mode = 0644
|
||||
mode = 0o644
|
||||
}
|
||||
hdr := &tar.Header{
|
||||
Name: file,
|
||||
|
|
@ -809,9 +806,11 @@ type byPortAndProtocol []string
|
|||
func (s byPortAndProtocol) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s byPortAndProtocol) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
func (s byPortAndProtocol) Less(i, j int) bool {
|
||||
iSplit := strings.Split(string(s[i]), "/")
|
||||
iPort, _ := strconv.Atoi(iSplit[0])
|
||||
|
|
@ -821,7 +820,7 @@ func (s byPortAndProtocol) Less(i, j int) bool {
|
|||
}
|
||||
|
||||
func flattenContainerPorts(in nat.PortMap) []interface{} {
|
||||
var out = make([]interface{}, 0)
|
||||
out := make([]interface{}, 0)
|
||||
|
||||
var internalPortKeys []string
|
||||
for portAndProtocolKeys := range in {
|
||||
|
|
@ -846,8 +845,9 @@ func flattenContainerPorts(in nat.PortMap) []interface{} {
|
|||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func flattenContainerNetworks(in *types.NetworkSettings) []interface{} {
|
||||
var out = make([]interface{}, 0)
|
||||
out := make([]interface{}, 0)
|
||||
if in == nil || in.Networks == nil || len(in.Networks) == 0 {
|
||||
return out
|
||||
}
|
||||
|
|
@ -912,7 +912,6 @@ func mapTypeMapValsToStringSlice(typeMap map[string]interface{}) []string {
|
|||
|
||||
func fetchDockerContainer(ID string, client *client.Client) (*types.Container, error) {
|
||||
apiContainers, err := client.ContainerList(context.Background(), types.ContainerListOptions{All: true})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error fetching container information from Docker: %s\n", err)
|
||||
}
|
||||
|
|
@ -973,6 +972,7 @@ func ulimitsToDockerUlimits(extraUlimits *schema.Set) []*units.Ulimit {
|
|||
|
||||
return retExtraUlimits
|
||||
}
|
||||
|
||||
func extraHostsSetToDockerExtraHosts(extraHosts *schema.Set) []string {
|
||||
retExtraHosts := []string{}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,9 +47,11 @@ type byPort []mappedPort
|
|||
func (s byPort) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s byPort) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
func (s byPort) Less(i, j int) bool {
|
||||
return s[i].internal < s[j].internal
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package docker
|
|||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -15,8 +16,6 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
||||
|
|
@ -2071,6 +2070,7 @@ resource "docker_container" "foo" {
|
|||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerPortConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "nginx:latest"
|
||||
|
|
@ -2087,6 +2087,7 @@ resource "docker_container" "foo" {
|
|||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerMultiplePortConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "nginx:latest"
|
||||
|
|
@ -2160,6 +2161,7 @@ resource "docker_container" "foo" {
|
|||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerNoStartConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "nginx:latest"
|
||||
|
|
@ -2173,6 +2175,7 @@ resource "docker_container" "foo" {
|
|||
must_run = false
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerNetworksIPv4AddressConfig = `
|
||||
resource "docker_network" "test" {
|
||||
name = "tf-test"
|
||||
|
|
@ -2193,6 +2196,7 @@ resource "docker_container" "foo" {
|
|||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerNetworksIPv6AddressConfig = `
|
||||
resource "docker_network" "test" {
|
||||
name = "tf-test"
|
||||
|
|
@ -2215,6 +2219,7 @@ resource "docker_container" "foo" {
|
|||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerNetworksDualStackAddressConfig = `
|
||||
resource "docker_network" "test" {
|
||||
name = "tf-test"
|
||||
|
|
@ -2242,6 +2247,7 @@ resource "docker_container" "foo" {
|
|||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerRmConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "busybox:latest"
|
||||
|
|
@ -2254,6 +2260,7 @@ resource "docker_image" "foo" {
|
|||
rm = true
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerReadOnlyConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "busybox:latest"
|
||||
|
|
@ -2266,6 +2273,7 @@ resource "docker_image" "foo" {
|
|||
read_only = true
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerAttachConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "busybox:latest"
|
||||
|
|
@ -2279,6 +2287,7 @@ resource "docker_image" "foo" {
|
|||
must_run = false
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerLogsConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "busybox:latest"
|
||||
|
|
@ -2294,6 +2303,7 @@ resource "docker_container" "foo" {
|
|||
must_run = false
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerExitCodeConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "busybox:latest"
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
|||
|
||||
func resourceDockerContainerV1() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
//This is only used for state migration, so the CRUD
|
||||
//callbacks are no longer relevant
|
||||
// This is only used for state migration, so the CRUD
|
||||
// callbacks are no longer relevant
|
||||
SchemaVersion: 1,
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/docker/cli/cli/command/image/build"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ func testAccDockerImageDestroy(s *terraform.State) error {
|
|||
func TestAccDockerImage_build(t *testing.T) {
|
||||
wd, _ := os.Getwd()
|
||||
dfPath := path.Join(wd, "Dockerfile")
|
||||
ioutil.WriteFile(dfPath, []byte(testDockerFileExample), 0644)
|
||||
ioutil.WriteFile(dfPath, []byte(testDockerFileExample), 0o644)
|
||||
defer os.Remove(dfPath)
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ func resourceDockerNetwork() *schema.Resource {
|
|||
|
||||
func resourceDockerNetworkV0() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
//This is only used for state migration, so the CRUD
|
||||
//callbacks are no longer relevant
|
||||
// This is only used for state migration, so the CRUD
|
||||
// callbacks are no longer relevant
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
|
@ -207,7 +206,7 @@ func resourceDockerNetworkRemoveRefreshFunc(
|
|||
// TODO mavogel: separate structure file
|
||||
// TODO 2: seems like we can replace the set hash generation with plain lists -> #219
|
||||
func flattenIpamConfigSpec(in []network.IPAMConfig) *schema.Set { // []interface{} {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
log.Printf("[DEBUG] flatten ipam %d: %#v", i, v)
|
||||
m := make(map[string]interface{})
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
||||
|
|
|
|||
|
|
@ -26,119 +26,119 @@ func resourceDockerRegistryImage() *schema.Resource {
|
|||
Default: false,
|
||||
},
|
||||
|
||||
"build": &schema.Schema{
|
||||
"build": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"suppress_output": &schema.Schema{
|
||||
"suppress_output": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"remote_context": &schema.Schema{
|
||||
"remote_context": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"no_cache": &schema.Schema{
|
||||
"no_cache": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"remove": &schema.Schema{
|
||||
"remove": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"force_remove": &schema.Schema{
|
||||
"force_remove": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"pull_parent": &schema.Schema{
|
||||
"pull_parent": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"isolation": &schema.Schema{
|
||||
"isolation": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"cpu_set_cpus": &schema.Schema{
|
||||
"cpu_set_cpus": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"cpu_set_mems": &schema.Schema{
|
||||
"cpu_set_mems": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"cpu_shares": &schema.Schema{
|
||||
"cpu_shares": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"cpu_quota": &schema.Schema{
|
||||
"cpu_quota": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"cpu_period": &schema.Schema{
|
||||
"cpu_period": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"memory": &schema.Schema{
|
||||
"memory": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"memory_swap": &schema.Schema{
|
||||
"memory_swap": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"cgroup_parent": &schema.Schema{
|
||||
"cgroup_parent": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"network_mode": &schema.Schema{
|
||||
"network_mode": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"shm_size": &schema.Schema{
|
||||
"shm_size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"dockerfile": &schema.Schema{
|
||||
"dockerfile": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "Dockerfile",
|
||||
ForceNew: true,
|
||||
},
|
||||
"ulimit": &schema.Schema{
|
||||
"ulimit": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"hard": &schema.Schema{
|
||||
"hard": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"soft": &schema.Schema{
|
||||
"soft": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
|
|
@ -146,7 +146,7 @@ func resourceDockerRegistryImage() *schema.Resource {
|
|||
},
|
||||
},
|
||||
},
|
||||
"build_args": &schema.Schema{
|
||||
"build_args": {
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
|
@ -154,47 +154,47 @@ func resourceDockerRegistryImage() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"auth_config": &schema.Schema{
|
||||
"auth_config": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"host_name": &schema.Schema{
|
||||
"host_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"user_name": &schema.Schema{
|
||||
"user_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"password": &schema.Schema{
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"auth": &schema.Schema{
|
||||
"auth": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"email": &schema.Schema{
|
||||
"email": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"server_address": &schema.Schema{
|
||||
"server_address": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"identity_token": &schema.Schema{
|
||||
"identity_token": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"registry_token": &schema.Schema{
|
||||
"registry_token": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"context": &schema.Schema{
|
||||
"context": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
|
|
@ -206,7 +206,7 @@ func resourceDockerRegistryImage() *schema.Resource {
|
|||
return val.(string) + ":" + contextTarHash
|
||||
},
|
||||
},
|
||||
"labels": &schema.Schema{
|
||||
"labels": {
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
|
@ -214,12 +214,12 @@ func resourceDockerRegistryImage() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"squash": &schema.Schema{
|
||||
"squash": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"cache_from": &schema.Schema{
|
||||
"cache_from": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
|
@ -227,7 +227,7 @@ func resourceDockerRegistryImage() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"security_opt": &schema.Schema{
|
||||
"security_opt": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
|
@ -235,7 +235,7 @@ func resourceDockerRegistryImage() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"extra_hosts": &schema.Schema{
|
||||
"extra_hosts": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
|
@ -243,27 +243,27 @@ func resourceDockerRegistryImage() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"target": &schema.Schema{
|
||||
"target": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"session_id": &schema.Schema{
|
||||
"session_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"platform": &schema.Schema{
|
||||
"platform": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"version": &schema.Schema{
|
||||
"version": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"build_id": &schema.Schema{
|
||||
"build_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ type internalPushImageOptions struct {
|
|||
}
|
||||
|
||||
func createImageBuildOptions(buildOptions map[string]interface{}) types.ImageBuildOptions {
|
||||
|
||||
mapOfInterfacesToMapOfStrings := func(mapOfInterfaces map[string]interface{}) map[string]string {
|
||||
mapOfStrings := make(map[string]string, len(mapOfInterfaces))
|
||||
for k, v := range mapOfInterfaces {
|
||||
|
|
@ -133,7 +132,6 @@ func createImageBuildOptions(buildOptions map[string]interface{}) types.ImageBui
|
|||
}
|
||||
|
||||
func buildDockerRegistryImage(client *client.Client, buildOptions map[string]interface{}, fqName string) error {
|
||||
|
||||
type ErrorDetailMessage struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
|
|
@ -213,7 +211,6 @@ func buildDockerImageContextTar(buildContext string) (string, error) {
|
|||
defer tw.Close()
|
||||
|
||||
err = filepath.Walk(buildContext, func(file string, info os.FileInfo, err error) error {
|
||||
|
||||
// return on any error
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -254,7 +251,6 @@ func buildDockerImageContextTar(buildContext string) (string, error) {
|
|||
f.Close()
|
||||
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
return tmpFile.Name(), nil
|
||||
|
|
@ -358,7 +354,6 @@ func deleteDockerRegistryImage(pushOpts internalPushImageOptions, sha256Digest,
|
|||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error during registry request: %s", err)
|
||||
}
|
||||
|
|
@ -376,7 +371,6 @@ func deleteDockerRegistryImage(pushOpts internalPushImageOptions, sha256Digest,
|
|||
params.Set("service", auth["service"])
|
||||
params.Set("scope", auth["scope"])
|
||||
tokenRequest, err := http.NewRequest("GET", auth["realm"]+"?"+params.Encode(), nil)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating registry request: %s", err)
|
||||
}
|
||||
|
|
@ -386,7 +380,6 @@ func deleteDockerRegistryImage(pushOpts internalPushImageOptions, sha256Digest,
|
|||
}
|
||||
|
||||
tokenResponse, err := client.Do(tokenRequest)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error during registry request: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import (
|
|||
)
|
||||
|
||||
func TestAccDockerRegistryImageResource_mapping(t *testing.T) {
|
||||
|
||||
assert := func(condition bool, msg string) {
|
||||
if !condition {
|
||||
t.Errorf("assertion failed: wrong build parameter %s", msg)
|
||||
|
|
@ -102,7 +101,6 @@ func TestAccDockerRegistryImageResource_mapping(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestAccDockerRegistryImageResource_build(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"log"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
)
|
||||
|
|
@ -55,8 +54,8 @@ func resourceDockerSecret() *schema.Resource {
|
|||
|
||||
func resourceDockerSecretV0() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
//This is only used for state migration, so the CRUD
|
||||
//callbacks are no longer relevant
|
||||
// This is only used for state migration, so the CRUD
|
||||
// callbacks are no longer relevant
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
|
|
@ -111,7 +110,6 @@ func resourceDockerSecretCreate(d *schema.ResourceData, meta interface{}) error
|
|||
func resourceDockerSecretRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ProviderConfig).DockerClient
|
||||
secret, _, err := client.SecretInspectWithRaw(context.Background(), d.Id())
|
||||
|
||||
if err != nil {
|
||||
log.Printf("[WARN] Secret (%s) not found, removing from state", d.Id())
|
||||
d.SetId("")
|
||||
|
|
@ -128,7 +126,6 @@ func resourceDockerSecretRead(d *schema.ResourceData, meta interface{}) error {
|
|||
func resourceDockerSecretDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ProviderConfig).DockerClient
|
||||
err := client.SecretRemove(context.Background(), d.Id())
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ func resourceDockerService() *schema.Resource {
|
|||
Type: schema.TypeInt,
|
||||
Description: "Represents represents the FileMode of the file",
|
||||
Optional: true,
|
||||
Default: 0444,
|
||||
Default: 0o444,
|
||||
ValidateFunc: validateIntegerGeqThan(0),
|
||||
},
|
||||
},
|
||||
|
|
@ -482,7 +482,7 @@ func resourceDockerService() *schema.Resource {
|
|||
Type: schema.TypeInt,
|
||||
Description: "Represents represents the FileMode of the file",
|
||||
Optional: true,
|
||||
Default: 0444,
|
||||
Default: 0o444,
|
||||
ValidateFunc: validateIntegerGeqThan(0),
|
||||
},
|
||||
},
|
||||
|
|
@ -958,8 +958,8 @@ func resourceDockerService() *schema.Resource {
|
|||
|
||||
func resourceDockerServiceV0() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
//This is only used for state migration, so the CRUD
|
||||
//callbacks are no longer relevant
|
||||
// This is only used for state migration, so the CRUD
|
||||
// callbacks are no longer relevant
|
||||
Schema: map[string]*schema.Schema{
|
||||
"auth": {
|
||||
Type: schema.TypeMap,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package docker
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
|
@ -10,8 +11,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"encoding/base64"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
|
|
@ -252,7 +251,6 @@ func resourceDockerServiceDelete(d *schema.ResourceData, meta interface{}) error
|
|||
// fetchDockerService fetches a service by its name or id
|
||||
func fetchDockerService(ID string, name string, client *client.Client) (*swarm.Service, error) {
|
||||
apiServices, err := client.ServiceList(context.Background(), types.ServiceListOptions{})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error fetching service information from Docker: %s", err)
|
||||
}
|
||||
|
|
@ -599,7 +597,6 @@ func terminalState(state swarm.TaskState) bool {
|
|||
//////// Mappers
|
||||
// createServiceSpec creates the service spec: https://docs.docker.com/engine/api/v1.32/#operation/ServiceCreate
|
||||
func createServiceSpec(d *schema.ResourceData) (swarm.ServiceSpec, error) {
|
||||
|
||||
serviceSpec := swarm.ServiceSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
Name: d.Get("name").(string),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
|
@ -8,8 +9,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ func resourceDockerVolume() *schema.Resource {
|
|||
|
||||
func resourceDockerVolumeV0() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
//This is only used for state migration, so the CRUD
|
||||
//callbacks are no longer relevant
|
||||
// This is only used for state migration, so the CRUD
|
||||
// callbacks are no longer relevant
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func flattenServiceMode(in swarm.ServiceMode) []interface{} {
|
|||
}
|
||||
|
||||
func flattenReplicated(in *swarm.ReplicatedService) []interface{} {
|
||||
var out = make([]interface{}, 0, 0)
|
||||
out := make([]interface{}, 0, 0)
|
||||
m := make(map[string]interface{})
|
||||
if in != nil {
|
||||
if in.Replicas != nil {
|
||||
|
|
@ -69,7 +69,7 @@ func flattenReplicated(in *swarm.ReplicatedService) []interface{} {
|
|||
}
|
||||
|
||||
func flattenServiceUpdateOrRollbackConfig(in *swarm.UpdateConfig) []interface{} {
|
||||
var out = make([]interface{}, 0, 0)
|
||||
out := make([]interface{}, 0, 0)
|
||||
if in == nil {
|
||||
return out
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ func flattenServiceUpdateOrRollbackConfig(in *swarm.UpdateConfig) []interface{}
|
|||
}
|
||||
|
||||
func flattenServiceEndpoint(in swarm.Endpoint) []interface{} {
|
||||
var out = make([]interface{}, 0, 0)
|
||||
out := make([]interface{}, 0, 0)
|
||||
m := make(map[string]interface{})
|
||||
m["mode"] = string(in.Spec.Mode)
|
||||
m["ports"] = flattenServicePorts(in.Ports)
|
||||
|
|
@ -96,7 +96,7 @@ func flattenServiceEndpoint(in swarm.Endpoint) []interface{} {
|
|||
}
|
||||
|
||||
func flattenServiceEndpointSpec(in *swarm.EndpointSpec) []interface{} {
|
||||
var out = make([]interface{}, 0, 0)
|
||||
out := make([]interface{}, 0, 0)
|
||||
m := make(map[string]interface{})
|
||||
m["mode"] = string(in.Mode)
|
||||
m["ports"] = flattenServicePorts(in.Ports)
|
||||
|
|
@ -107,7 +107,7 @@ func flattenServiceEndpointSpec(in *swarm.EndpointSpec) []interface{} {
|
|||
|
||||
///// start TaskSpec
|
||||
func flattenContainerSpec(in *swarm.ContainerSpec) []interface{} {
|
||||
var out = make([]interface{}, 0, 0)
|
||||
out := make([]interface{}, 0, 0)
|
||||
m := make(map[string]interface{})
|
||||
if len(in.Image) > 0 {
|
||||
m["image"] = in.Image
|
||||
|
|
@ -178,7 +178,7 @@ func flattenPrivileges(in *swarm.Privileges) []interface{} {
|
|||
return make([]interface{}, 0, 0)
|
||||
}
|
||||
|
||||
var out = make([]interface{}, 1, 1)
|
||||
out := make([]interface{}, 1, 1)
|
||||
m := make(map[string]interface{})
|
||||
|
||||
if in.CredentialSpec != nil {
|
||||
|
|
@ -205,7 +205,7 @@ func flattenPrivileges(in *swarm.Privileges) []interface{} {
|
|||
}
|
||||
|
||||
func flattenServiceMounts(in []mount.Mount) *schema.Set {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
m := make(map[string]interface{})
|
||||
m["target"] = v.Target
|
||||
|
|
@ -266,7 +266,7 @@ func flattenServiceHealthcheck(in *container.HealthConfig) []interface{} {
|
|||
return make([]interface{}, 0, 0)
|
||||
}
|
||||
|
||||
var out = make([]interface{}, 1, 1)
|
||||
out := make([]interface{}, 1, 1)
|
||||
m := make(map[string]interface{})
|
||||
if len(in.Test) > 0 {
|
||||
m["test"] = in.Test
|
||||
|
|
@ -280,7 +280,7 @@ func flattenServiceHealthcheck(in *container.HealthConfig) []interface{} {
|
|||
}
|
||||
|
||||
func flattenServiceHosts(in []string) *schema.Set {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
m := make(map[string]interface{})
|
||||
split := strings.Split(v, ":")
|
||||
|
|
@ -300,7 +300,7 @@ func flattenServiceDNSConfig(in *swarm.DNSConfig) []interface{} {
|
|||
return make([]interface{}, 0, 0)
|
||||
}
|
||||
|
||||
var out = make([]interface{}, 1, 1)
|
||||
out := make([]interface{}, 1, 1)
|
||||
m := make(map[string]interface{})
|
||||
if len(in.Nameservers) > 0 {
|
||||
m["nameservers"] = in.Nameservers
|
||||
|
|
@ -316,7 +316,7 @@ func flattenServiceDNSConfig(in *swarm.DNSConfig) []interface{} {
|
|||
}
|
||||
|
||||
func flattenServiceSecrets(in []*swarm.SecretReference) *schema.Set {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
m := make(map[string]interface{})
|
||||
m["secret_id"] = v.SecretID
|
||||
|
|
@ -343,7 +343,7 @@ func flattenServiceSecrets(in []*swarm.SecretReference) *schema.Set {
|
|||
}
|
||||
|
||||
func flattenServiceConfigs(in []*swarm.ConfigReference) *schema.Set {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
m := make(map[string]interface{})
|
||||
m["config_id"] = v.ConfigID
|
||||
|
|
@ -370,7 +370,7 @@ func flattenServiceConfigs(in []*swarm.ConfigReference) *schema.Set {
|
|||
}
|
||||
|
||||
func flattenTaskResources(in *swarm.ResourceRequirements) []interface{} {
|
||||
var out = make([]interface{}, 0, 0)
|
||||
out := make([]interface{}, 0, 0)
|
||||
if in != nil {
|
||||
m := make(map[string]interface{})
|
||||
m["limits"] = flattenResourceLimitsOrReservations(in.Limits)
|
||||
|
|
@ -381,7 +381,7 @@ func flattenTaskResources(in *swarm.ResourceRequirements) []interface{} {
|
|||
}
|
||||
|
||||
func flattenResourceLimitsOrReservations(in *swarm.Resources) []interface{} {
|
||||
var out = make([]interface{}, 0, 0)
|
||||
out := make([]interface{}, 0, 0)
|
||||
if in != nil {
|
||||
m := make(map[string]interface{})
|
||||
m["nano_cpus"] = in.NanoCPUs
|
||||
|
|
@ -393,7 +393,7 @@ func flattenResourceLimitsOrReservations(in *swarm.Resources) []interface{} {
|
|||
}
|
||||
|
||||
func flattenResourceGenericResource(in []swarm.GenericResource) []interface{} {
|
||||
var out = make([]interface{}, 0, 0)
|
||||
out := make([]interface{}, 0, 0)
|
||||
if in != nil && len(in) > 0 {
|
||||
m := make(map[string]interface{})
|
||||
named := make([]string, 0)
|
||||
|
|
@ -435,7 +435,7 @@ func flattenTaskPlacement(in *swarm.Placement) []interface{} {
|
|||
if in == nil {
|
||||
return make([]interface{}, 0, 0)
|
||||
}
|
||||
var out = make([]interface{}, 1, 1)
|
||||
out := make([]interface{}, 1, 1)
|
||||
m := make(map[string]interface{})
|
||||
if len(in.Constraints) > 0 {
|
||||
m["constraints"] = newStringSet(schema.HashString, in.Constraints)
|
||||
|
|
@ -455,7 +455,7 @@ func flattenPlacementPrefs(in []swarm.PlacementPreference) *schema.Set {
|
|||
return schema.NewSet(schema.HashString, make([]interface{}, 0, 0))
|
||||
}
|
||||
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
out[i] = v.Spread.SpreadDescriptor
|
||||
}
|
||||
|
|
@ -463,7 +463,7 @@ func flattenPlacementPrefs(in []swarm.PlacementPreference) *schema.Set {
|
|||
}
|
||||
|
||||
func flattenPlacementPlatforms(in []swarm.Platform) *schema.Set {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
m := make(map[string]interface{})
|
||||
m["architecture"] = v.Architecture
|
||||
|
|
@ -477,7 +477,7 @@ func flattenPlacementPlatforms(in []swarm.Platform) *schema.Set {
|
|||
}
|
||||
|
||||
func flattenTaskNetworks(in []swarm.NetworkAttachmentConfig) *schema.Set {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
out[i] = v.Target
|
||||
}
|
||||
|
|
@ -489,7 +489,7 @@ func flattenTaskLogDriver(in *swarm.Driver) []interface{} {
|
|||
return make([]interface{}, 0, 0)
|
||||
}
|
||||
|
||||
var out = make([]interface{}, 1, 1)
|
||||
out := make([]interface{}, 1, 1)
|
||||
m := make(map[string]interface{})
|
||||
m["name"] = in.Name
|
||||
if len(in.Options) > 0 {
|
||||
|
|
@ -502,7 +502,7 @@ func flattenTaskLogDriver(in *swarm.Driver) []interface{} {
|
|||
///// end TaskSpec
|
||||
///// start EndpointSpec
|
||||
func flattenServicePorts(in []swarm.PortConfig) []interface{} {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
m := make(map[string]interface{})
|
||||
m["name"] = v.Name
|
||||
|
|
@ -530,7 +530,7 @@ func shortDur(d time.Duration) string {
|
|||
}
|
||||
|
||||
func newStringSet(f schema.SchemaSetFunc, in []string) *schema.Set {
|
||||
var out = make([]interface{}, len(in), len(in))
|
||||
out := make([]interface{}, len(in), len(in))
|
||||
for i, v := range in {
|
||||
out[i] = v
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ func validateStringIsBase64Encoded() schema.SchemaValidateFunc {
|
|||
}
|
||||
|
||||
func validateDockerContainerPath(v interface{}, k string) (ws []string, errors []error) {
|
||||
|
||||
value := v.(string)
|
||||
if !regexp.MustCompile(`^[a-zA-Z]:\\|^/`).MatchString(value) {
|
||||
errors = append(errors, fmt.Errorf("%q must be an absolute path", k))
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ func TestValidateFloatRatio(t *testing.T) {
|
|||
t.Fatalf("%v should be an invalid float greater than 1.0", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateStringIsFloatRatio(t *testing.T) {
|
||||
v := "0.9"
|
||||
if _, error := validateStringIsFloatRatio()(v, "name"); error != nil {
|
||||
|
|
@ -86,6 +87,7 @@ func TestValidateStringIsFloatRatio(t *testing.T) {
|
|||
t.Fatalf("%v should be an invalid float because it is an int out of range", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateDurationGeq0(t *testing.T) {
|
||||
v := "1ms"
|
||||
if _, error := validateDurationGeq0()(v, "name"); error != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue