docker-compose.yml到Terraform.tf

问题描述 投票:0回答:0

main.tf看起来像这样:

resource "docker_container" "myapp" { name = "myapp" image = "myapphub/myapp" }

和变量。tf看起来像这样:

resource "docker_volume" "my_volume" { name = "my-volume" variable "container_name" { description = "Value of the name for the Docker container" type = string default = "ExampleNginxContainer" }

那么,我将如何将Docker-Compose.yml中包含的所有其他指令纳入Terraform.tf?还是我试图将叉子用作勺子的地方?
network_mode: host cap_add: - NET_ADMIN devices: - /dev/net/tun environment: MYAPP_ENROLMENT_KEY: ?? how do i get this from variables.tf ?? volumes: - myapp-config:/etc/myapp/profiles - myapp-logs:/var/log/myapp restart: unless-stopped

我没有使用此提供商,但是查看DOC您的Docker-Compose文件中的所有内容都在Terraform配置中具有相应的属性。我在大约5分钟内将其敲了一下,您可能需要对其进行一些调整,但应该给您足够的开始才能开始。
除非我想念您的问题。

terraform { required_providers { docker = { source = "kreuzwerker/docker" version = "3.0.2" } } } variable "enrolment_key" { description = "The enrolment key for the app" type = string } resource "docker_container" "myapp" { name = "myapp" image = "myapphub/myapp" network_mode = "host" capabilities { add = ["NET_ADMIN"] } devices { host_path = "/dev/net/tun" } env = [ "MYAPP_ENROLMENT_KEY: ${var.enrolment_key}", ] volumes { volume_name = docker_volume.myapp_config.name container_path = "/etc/myapp/profiles" } volumes { volume_name = docker_volume.myapp_logs.name container_path = "/var/log/myapp" } restart = "unless-stopped" } resource "docker_container" "watchtower" { image = "containrrr/watchtower" name = "watchtower" volumes { host_path = "/var/run/docker.sock" container_path = "/var/run/docker.sock" } restart = "unless-stopped" } resource "docker_volume" "myapp_config" { name = "myapp-config" } resource "docker_volume" "myapp_logs" { name = "myapp-logs" }

	
docker docker-compose terraform
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.