Skip to main content

One post tagged with "cicd"

View All Tags

· One min read

doc

install

https://www.terraform.io/downloads.html

wget https://releases.hashicorp.com/terraform/0.12.18/terraform_0.12.18_linux_amd64.zip
unzip terraform_0.12.18_linux_amd64.zip -d .
mv terraform /usr/bin/

cache

export TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/plugin-cache" # windows is must
~/.terraform.rc

tee ~/.terraformrc <<-'EOF'
plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
disable_checkpoint = true
EOF

cmd

  • terraform init
  • terraform apply -target=docker_container.mysql-1
provider "docker" {
default = "unix:///var/run/docker.sock"
# default = "tcp://127.0.0.1:2375"
}

variable "edf" {
default = "qqqq"
}

resource "docker_container" "ptest" {
name = "ptest"
image = "ptest"
ports {
internal = 5000
external = 2222
}
provisioner "local-exec" {
command = "echo ${var.password}"
}
}

resource "docker_container" "mysql-1" {
restart = "unless-stopped"
name = "mysql-1"
image = "mysql:8.0.15"
command = [
"--character-set-server=utf8mb4",
"--collation-server=utf8mb4_unicode_ci",
]
env = [
"MYSQL_ROOT_PASSWORD=${var.password}",
"TZ=Asia/Shanghai",
]
ports {
internal = 3306
external = 3306
}
}