mirror of
https://github.com/Dannecron/netology-devops-gw-infra.git
synced 2025-12-25 15:22:36 +03:00
[stage-2] add cluster terraform-configuration
This commit is contained in:
38
terraform/cluster.tf
Normal file
38
terraform/cluster.tf
Normal file
@@ -0,0 +1,38 @@
|
||||
resource "random_shuffle" "netology-gw-subnet-random" {
|
||||
input = [yandex_vpc_subnet.netology-gw-subnet-a.id, yandex_vpc_subnet.netology-gw-subnet-b.id]
|
||||
result_count = 1
|
||||
}
|
||||
|
||||
resource "yandex_compute_instance" "k8s-cluster" {
|
||||
for_each = toset(["control", "node01", "node2"])
|
||||
|
||||
name = each.key
|
||||
|
||||
resources {
|
||||
cores = 2
|
||||
memory = 2
|
||||
}
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image_id = "fd8kdq6d0p8sij7h5qe3" # ubuntu-20-04-lts-v20220822
|
||||
size = "20"
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnet_id = random_shuffle.netology-gw-subnet-random.result
|
||||
nat = true
|
||||
}
|
||||
|
||||
metadata = {
|
||||
ssh-keys = "ubuntu:${file("~/.ssh/id_rsa.pub")}"
|
||||
}
|
||||
}
|
||||
|
||||
output "cluster_ips" {
|
||||
value = {
|
||||
internal = values(yandex_compute_instance.k8s-cluster)[*].network_interface.0.ip_address
|
||||
external = values(yandex_compute_instance.k8s-cluster)[*].network_interface.0.nat_ip_address
|
||||
}
|
||||
}
|
||||
@@ -41,19 +41,20 @@
|
||||
- "'AlreadyExists' not in bucket_create_result.stderr"
|
||||
- name: Terraform - Create variables.tf
|
||||
ansible.builtin.template:
|
||||
src: "templates/variables.tf.j2"
|
||||
dest: "terraform/variables.tf"
|
||||
src: "{{ playbook_dir }}/templates/terraform/variables.tf.j2"
|
||||
dest: "{{ playbook_dir }}/terraform/variables.tf"
|
||||
- name: Terraform - init
|
||||
ansible.builtin.command:
|
||||
chdir: ./terraform
|
||||
chdir: "{{ playbook_dir }}/terraform"
|
||||
cmd: >-
|
||||
terraform init
|
||||
-reconfigure
|
||||
-backend-config="bucket={{ terraform_yandex_bucket_name }}"
|
||||
-backend-config="access_key={{ service_account_key_id }}"
|
||||
-backend-config="secret_key={{ service_account_secret }}"
|
||||
- name: Terraform - create workspace
|
||||
ansible.builtin.command:
|
||||
chdir: ./terraform
|
||||
chdir: "{{ playbook_dir }}/terraform"
|
||||
cmd: terraform workspace new prod
|
||||
register: terraform_new_workspace_result
|
||||
failed_when:
|
||||
|
||||
Reference in New Issue
Block a user