From b9c54eff607ee8da316de6f7bbb77a47c6a63e0a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 8 Oct 2022 19:52:45 +0200 Subject: [PATCH] first test terraform to create cluster k8s --- main.tf | 43 ------------------------------ scaleway-k8s/tasks/main.yml | 20 ++++++-------- scaleway-k8s/templates/main.tf.j2 | 44 ------------------------------- 3 files changed, 8 insertions(+), 99 deletions(-) delete mode 100644 main.tf diff --git a/main.tf b/main.tf deleted file mode 100644 index 2aa7a66..0000000 --- a/main.tf +++ /dev/null @@ -1,43 +0,0 @@ -terraform { - required_providers { - scaleway = { - source = "scaleway/scaleway" - } - } - required_version = ">= 0.13" -} - -resource "scaleway_k8s_cluster" "terraform-test" { - name = "terraform-test" - version = "1.24.3" - cni = "cilium" - project_id = "81af2696-6120-4f45-baf3-d17fb0525824" - region = "fr-par" -} - - resource "scaleway_k8s_pool" "john" { - cluster_id = scaleway_k8s_cluster.terraform-test.id - name = "john" - node_type = "DEV1-M" - size = 1 - } - - resource "null_resource" "kubeconfig" { - depends_on = [scaleway_k8s_pool.john] # at least one pool here - triggers = { - host = scaleway_k8s_cluster.terraform-test.kubeconfig[0].host - token = scaleway_k8s_cluster.terraform-test.kubeconfig[0].token - cluster_ca_certificate = scaleway_k8s_cluster.terraform-test.kubeconfig[0].cluster_ca_certificate - } -} - - -provider "kubernetes" { - load_config_file = "false" - - host = null_resource.kubeconfig.triggers.host - token = null_resource.kubeconfig.triggers.token - cluster_ca_certificate = base64decode( - null_resource.kubeconfig.triggers.cluster_ca_certificate - ) -} \ No newline at end of file diff --git a/scaleway-k8s/tasks/main.yml b/scaleway-k8s/tasks/main.yml index c3c3ad3..c429ca0 100644 --- a/scaleway-k8s/tasks/main.yml +++ b/scaleway-k8s/tasks/main.yml @@ -1,24 +1,15 @@ --- # tasks file for scaleway-k8s -- name: Create directory terraform +- name: Create directory {{ project_terraform }} file: - path: /home/valentin/terraform + path: "{{ project_terraform }}" state: directory - name: Copy main.tf template: src: main.tf.j2 - dest: /home/valentin/terraform/main.tf - -- name: Plan terraform - community.general.terraform: - project_path: '{{ project_terraform }}' - state: planned - register: output - environment: - SCW_ACCESS_KEY: "{{ scw_access_key }}" - SCW_SECRET_KEY: "{{ scw_secret_key }}" + dest: "{{ project_terraform }}/main.tf" - name: display plan terraform @@ -29,8 +20,13 @@ community.general.terraform: project_path: '{{ project_terraform }}' state: present + force_init: yes environment: SCW_ACCESS_KEY: "{{ scw_access_key }}" SCW_SECRET_KEY: "{{ scw_secret_key }}" + register: output +- name: display terraform result + debug: + var: output diff --git a/scaleway-k8s/templates/main.tf.j2 b/scaleway-k8s/templates/main.tf.j2 index 9c1cf05..e69de29 100644 --- a/scaleway-k8s/templates/main.tf.j2 +++ b/scaleway-k8s/templates/main.tf.j2 @@ -1,44 +0,0 @@ -terraform { - required_providers { - scaleway = { - source = "scaleway/scaleway" - } - } - required_version = ">= 0.13" -} - - - resource "scaleway_k8s_cluster" "{{ project_name }}" { - name = "{{ project_name }}" - version = "1.24.3" - cni = "cilium" - project_id = "{{ project_id }}" - region = "{{ region_k8s }}" - } - - resource "scaleway_k8s_pool" "john" { - cluster_id = scaleway_k8s_cluster.{{ project_name }}.id - name = "john" - node_type = "DEV1-M" - size = 1 - } - - resource "null_resource" "kubeconfig" { - depends_on = [scaleway_k8s_pool.john] # at least one pool here - triggers = { - host = scaleway_k8s_cluster.{{ project_name }}.kubeconfig[0].host - token = scaleway_k8s_cluster.{{ project_name }}.kubeconfig[0].token - cluster_ca_certificate = scaleway_k8s_cluster.{{ project_name }}.kubeconfig[0].cluster_ca_certificate - } -} - - -provider "kubernetes" { - load_config_file = "false" - - host = null_resource.kubeconfig.triggers.host - token = null_resource.kubeconfig.triggers.token - cluster_ca_certificate = base64decode( - null_resource.kubeconfig.triggers.cluster_ca_certificate - ) -} \ No newline at end of file