You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/testing/deployer/sprawl/internal/tfgen/docker.go

46 lines
864 B

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package tfgen
import (
"fmt"
"regexp"
)
var invalidResourceName = regexp.MustCompile(`[^a-z0-9-]+`)
func DockerImageResourceName(image string) string {
if image == "" {
panic(`image must not be ""`)
}
return invalidResourceName.ReplaceAllLiteralString(image, "-")
}
func DockerNetwork(name, subnet string) Resource {
return Text(fmt.Sprintf(`
resource "docker_network" %[1]q {
name = %[1]q
attachable = true
ipam_config {
subnet = %[2]q
}
}
`, name, subnet))
}
func DockerVolume(name string) Resource {
return Text(fmt.Sprintf(`
resource "docker_volume" %[1]q {
name = %[1]q
}`, name))
}
func DockerImage(name, image string) Resource {
return Text(fmt.Sprintf(`
resource "docker_image" %[1]q {
name = %[2]q
keep_locally = true
}`, name, image))
}