-
Notifications
You must be signed in to change notification settings - Fork 0
/
providers.tf
56 lines (50 loc) · 1.79 KB
/
providers.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# App remote backend
# Remote backend for storing Terraform state for this deployment (the app)
terraform {
backend "s3" {
bucket = "seliot-terraform-state-bucket-arpio1"
key = "xyz_app_poc/terraform.tfstate"
dynamodb_table = "terraform-lock"
region = "us-east-1"
encrypt = true
}
}
# Infrastructure remote backend
# We use the remote backend state to retrieve the infrastructure outputs created by xyz_infra_poc
# We must pull from the appropriate workspace that corresponds to the environment stage we are deploying
# Terraform is weird and won't accept a `workspace` value in config, so instead we use it to form the S3 key
data "terraform_remote_state" "infra" {
backend = "s3"
config = {
bucket = "seliot-terraform-state-bucket-arpio1"
key = "env:/${var.workspace}/xyz_infra_poc/terraform.tfstate"
region = "us-east-1"
}
}
# Get the AWS Region from the infrastructure remote backend state
locals {
region = data.terraform_remote_state.infra.outputs.aws_region
}
# This tells Terraform which AWS region to look in for the EKS cluster
provider "aws" {
region = local.region
}
# Using the cluster name from the remote backend state, we retrieve data about the EKS cluster
data "aws_eks_cluster" "cluster" {
name = data.terraform_remote_state.infra.outputs.eks_cluster_name
}
# Define the kubernetes provider using the data from the EKS cluster
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
args = [
"eks",
"get-token",
"--cluster-name",
data.aws_eks_cluster.cluster.name
]
}
}