consul/testing/deployer/sprawl/internal/tfgen/docker.go

40 lines
740 B
Go
Raw Normal View History

package tfgen
import (
"fmt"
"regexp"
)
var invalidResourceName = regexp.MustCompile(`[^a-z0-9-]+`)
func DockerImageResourceName(image string) string {
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))
}