refactor(external): ask to enter variables if var file does not exist

This commit is contained in:
Khue Doan 2021-12-25 02:34:49 +07:00
parent c55b98186d
commit 08513dcda5
6 changed files with 48 additions and 14 deletions

View File

@ -1,11 +1,17 @@
.POSIX: .POSIX:
.EXPORT_ALL_VARIABLES:
KUBE_CONFIG_PATH = ../metal/kubeconfig.yaml
default: apply default: apply
~/.terraform.d/credentials.tfrc.json: ~/.terraform.d/credentials.tfrc.json:
terraform login terraform login
.terraform.lock.hcl: ~/.terraform.d/credentials.tfrc.json versions.tf terraform.tfvars:
ansible-playbook secrets.yml
.terraform.lock.hcl: ~/.terraform.d/credentials.tfrc.json versions.tf terraform.tfvars
terraform init terraform init
touch .terraform.lock.hcl touch .terraform.lock.hcl

View File

@ -1,7 +1,3 @@
variable "cloudflare_account_id" {
type = string
}
data "cloudflare_zone" "khuedoan_com" { data "cloudflare_zone" "khuedoan_com" {
name = "khuedoan.com" name = "khuedoan.com"
} }

View File

@ -4,14 +4,17 @@
vars_prompt: vars_prompt:
- name: cloudflare_email - name: cloudflare_email
prompt: Enter Cloudflare email prompt: Enter Cloudflare email
private: no
- name: cloudflare_api_key - name: cloudflare_api_key
prompt: Enter Cloudflare API Key prompt: Enter Cloudflare API Key (sensitive)
- name: cloudflare_account_id - name: cloudflare_account_id
prompt: Enter Cloudflare account ID prompt: Enter Cloudflare account ID
private: no
- name: b2_application_key_id - name: b2_application_key_id
prompt: Enter Backblaze application key ID prompt: Enter Backblaze application key ID
private: no
- name: b2_application_key - name: b2_application_key
prompt: Enter Backblaze application key prompt: Enter Backblaze application key (sensitive)
tasks: tasks:
- name: Ensure required namespaces exist - name: Ensure required namespaces exist
kubernetes.core.k8s: kubernetes.core.k8s:
@ -24,3 +27,7 @@
- cert-manager - cert-manager
- external-dns - external-dns
- cloudflared - cloudflared
- name: Render environment file
template:
src: ./terraform.tfvars.j2
dest: ./terraform.tfvars

View File

@ -0,0 +1,5 @@
cloudflare_email = "{{ cloudflare_email }}"
cloudflare_api_key = "{{ cloudflare_api_key }}"
cloudflare_account_id = "{{ cloudflare_account_id }}"
b2_application_key_id = "{{ b2_application_key_id }}"
b2_application_key = "{{ b2_application_key }}"

21
external/variables.tf Normal file
View File

@ -0,0 +1,21 @@
variable "cloudflare_email" {
type = string
}
variable "cloudflare_api_key" {
type = string
sensitive = true
}
variable "cloudflare_account_id" {
type = string
}
variable "b2_application_key_id" {
type = string
}
variable "b2_application_key" {
type = string
sensitive = true
}

View File

@ -34,17 +34,16 @@ terraform {
} }
provider "cloudflare" { provider "cloudflare" {
# Environment variables email = var.cloudflare_email
# CLOUDFLARE_API_TOKEN api_key = var.cloudflare_api_key
} }
provider "b2" { provider "b2" {
# Environment variables application_key_id = var.b2_application_key_id
# B2_APPLICATION_KEY application_key = var.b2_application_key
# B2_APPLICATION_KEY_ID
} }
provider "kubernetes" { provider "kubernetes" {
# Environment variables # Use KUBE_CONFIG_PATH environment variables
# KUBE_CONFIG_PATH # Or in cluster service account
} }