This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.tfstate # Состояние инфраструктуры | |
*.tfstate.backup # Бекап состояния инфраструктуры | |
.terraform/ # Директории модулей терраформа | |
terraform.tfvars # файл с переменными | |
.env # файл с переменными | |
*.pem # Ключи с расширением pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
backend "s3" { # Обозначение бекенда | |
bucket = "foo-terraform" # Имя бакета | |
key = "bucket/terraform.tfstate" # Ключ | |
region = "us-east-1" # Регион | |
encrypt = "true" # Включено ли шифрование | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "hcloud" { # Обозначение провайдера hetzner | |
token = "${var.hcloud_token}" # токен для подключения к API hetzner указывается в файле terraform.tfvars | |
} | |
# Ресурс рандом для генерации рандомных символов | |
resource "random_string" "name" { | |
length = 6 | |
special = false | |
upper = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Определение переменной токена | |
variable "hcloud_token" {} | |
# Определение переменной имени | |
variable "name" { | |
default = "foo" | |
} | |
# Определение переменной исходного образа ОС для инстанса | |
variable "image" { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "hcloud_server" "server" { # Create a server | |
name = "server-${local.name}" # Имя сервера | |
image = "${var.image}" # Базовый образ | |
server_type = "${var.server_type}" # Тип инстанса | |
location = "${var.location}" # Регион | |
backups = "false" # Включать ли бекапы | |
ssh_keys = ["${hcloud_ssh_key.user.id}"] # SSH ключ | |
user_data = "${data.template_file.instance.rendered}" # Скрипт, который отработает при старте | |
provisioner "file" { # Копирование файлов на инстанс |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
apt-get update | |
sudo apt-get install \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg2 \ | |
software-properties-common | |
# выполнение вышеобозначенных действий, также можно добавлять команды в зависимости от задачи. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hcloud_token = "токен который создали через веб интерфейс hetzner" | |
public_key = "публичный ssh ключ" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform init # Инициализация конфигов | |
terraform plan # Проверка действий | |
terraform apply # Запуск действий |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.tfstate # Infrastructure condition | |
*.tfstate.backup # Infrastructure state backup | |
.terraform/ # Terraform module directories | |
terraform.tfvars # variable file | |
.env # variable file | |
*.pem # Keys with pem extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
backend "s3" { # Backend designation | |
bucket = "foo-terraform" # Bucket name | |
key = "bucket/terraform.tfstate" # Key | |
region = "us-east-1" # Region | |
encrypt = "true" # Encryption enabled | |
} | |
} |
OlderNewer