[stage-2] add cluster terraform-configuration

This commit is contained in:
2023-03-16 11:13:01 +07:00
parent 787b053118
commit d4fee0e94e
3 changed files with 43 additions and 4 deletions

38
terraform/cluster.tf Normal file
View 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
}
}

View File

@@ -41,19 +41,20 @@
- "'AlreadyExists' not in bucket_create_result.stderr" - "'AlreadyExists' not in bucket_create_result.stderr"
- name: Terraform - Create variables.tf - name: Terraform - Create variables.tf
ansible.builtin.template: ansible.builtin.template:
src: "templates/variables.tf.j2" src: "{{ playbook_dir }}/templates/terraform/variables.tf.j2"
dest: "terraform/variables.tf" dest: "{{ playbook_dir }}/terraform/variables.tf"
- name: Terraform - init - name: Terraform - init
ansible.builtin.command: ansible.builtin.command:
chdir: ./terraform chdir: "{{ playbook_dir }}/terraform"
cmd: >- cmd: >-
terraform init terraform init
-reconfigure
-backend-config="bucket={{ terraform_yandex_bucket_name }}" -backend-config="bucket={{ terraform_yandex_bucket_name }}"
-backend-config="access_key={{ service_account_key_id }}" -backend-config="access_key={{ service_account_key_id }}"
-backend-config="secret_key={{ service_account_secret }}" -backend-config="secret_key={{ service_account_secret }}"
- name: Terraform - create workspace - name: Terraform - create workspace
ansible.builtin.command: ansible.builtin.command:
chdir: ./terraform chdir: "{{ playbook_dir }}/terraform"
cmd: terraform workspace new prod cmd: terraform workspace new prod
register: terraform_new_workspace_result register: terraform_new_workspace_result
failed_when: failed_when: