├── user-cluster ├── versions.tf ├── output.tf ├── provider.tf ├── main.tf ├── ssh.tf ├── cluster-ha.tf ├── files │ └── cloud-config.yaml ├── data.tf ├── infra.tf └── iam.tf ├── .pre-commit-config.yaml ├── install-app ├── provider.tf ├── data.tf └── main.tf ├── .gitignore ├── charts └── rio │ └── 0.0.1 │ ├── templates │ ├── service-account.yaml │ ├── cluster-role-binding.yaml │ ├── _helpers.tpl │ ├── deployment.yaml │ └── cluster-role.yaml │ ├── Chart.yaml │ ├── app-readme.md │ ├── values.yaml │ └── questions.yml └── Readme.MD /user-cluster/versions.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_version = ">= 0.12" 4 | } 5 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | - repo: git://github.com/antonbabenko/pre-commit-terraform 2 | rev: v1.19.0 3 | hooks: 4 | - id: terraform_fmt 5 | - id: terraform_docs 6 | -------------------------------------------------------------------------------- /install-app/provider.tf: -------------------------------------------------------------------------------- 1 | provider "rancher2" { 2 | api_url = data.terraform_remote_state.server.outputs.rancher_url 3 | token_key = data.terraform_remote_state.server.outputs.rancher_token 4 | } 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.tfstate* 3 | **/.terraform 4 | **/*.plan 5 | **/secret_files 6 | **/*.tfenvs 7 | **/aws_accounts/iam 8 | .DS_Store 9 | outputs/ 10 | terraform.d/ 11 | **/terraform.tfvars 12 | -------------------------------------------------------------------------------- /charts/rio/0.0.1/templates/service-account.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: ServiceAccount 4 | metadata: 5 | name: {{ template "rio.serviceAccountName" . }} 6 | namespace: {{ .Release.Namespace }} 7 | -------------------------------------------------------------------------------- /charts/rio/0.0.1/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | appVersion: 0.0.1 3 | description: Deploys Rio 4 | icon: https://github.com/rancher/ui/blob/master/public/assets/images/logos/welcome-cow.svg 5 | name: rio 6 | version: 0.0.1 7 | -------------------------------------------------------------------------------- /charts/rio/0.0.1/app-readme.md: -------------------------------------------------------------------------------- 1 | # Rio 2 | This catalog entry is for Rio. 3 | 4 | [Rio](https://github.com/rancher/rio) is a microPaaS for Kubernetes. 5 | 6 | Hopefully nobody reads this during the demo... I don't have a ton to say here in the example text. 7 | -------------------------------------------------------------------------------- /user-cluster/output.tf: -------------------------------------------------------------------------------- 1 | output "master_addresses" { 2 | value = aws_instance.cluster-master.*.public_ip 3 | } 4 | 5 | output "worker_addresses" { 6 | value = aws_instance.cluster-worker.*.public_ip 7 | } 8 | 9 | output "cluster_id" { 10 | value = rancher2_cluster.user-cluster.id 11 | } 12 | -------------------------------------------------------------------------------- /user-cluster/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | # profile = "rancher-eng" 4 | } 5 | 6 | provider "rancher2" { 7 | api_url = data.terraform_remote_state.server.outputs.rancher_url 8 | token_key = data.terraform_remote_state.server.outputs.rancher_token 9 | } 10 | -------------------------------------------------------------------------------- /user-cluster/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "remote" { 3 | organization = "drpebcak" 4 | workspaces { 5 | name = "rancher-as-code_user-cluster" 6 | } 7 | } 8 | } 9 | 10 | locals { 11 | name = "cluster-demo" 12 | rancher_version = "v2.2.8" 13 | instance_type = "t3.large" 14 | master_node_count = 3 15 | worker_node_count = 3 16 | } 17 | -------------------------------------------------------------------------------- /charts/rio/0.0.1/templates/cluster-role-binding.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRoleBinding 4 | metadata: 5 | name: rio-controller-binding 6 | roleRef: 7 | apiGroup: rbac.authorization.k8s.io 8 | kind: ClusterRole 9 | name: rio-cluster-admin 10 | subjects: 11 | - kind: ServiceAccount 12 | name: {{ template "rio.serviceAccountName" . }} 13 | namespace: {{ .Release.Namespace }} 14 | -------------------------------------------------------------------------------- /install-app/data.tf: -------------------------------------------------------------------------------- 1 | data "terraform_remote_state" "server" { 2 | backend = "remote" 3 | 4 | config = { 5 | organization = "drpebcak" 6 | workspaces = { 7 | name = "rancher-as-code_rancher-server" 8 | } 9 | } 10 | } 11 | 12 | data "terraform_remote_state" "cluster" { 13 | backend = "remote" 14 | 15 | config = { 16 | organization = "drpebcak" 17 | workspaces = { 18 | name = "rancher-as-code_user-cluster" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /charts/rio/0.0.1/values.yaml: -------------------------------------------------------------------------------- 1 | replicas: 1 2 | image: 3 | repository: "rancher/rio-controller" 4 | tag: "v0.5.0-alpha.5" 5 | pullPolicy: IfNotPresent 6 | serviceAccount: 7 | create: true 8 | name: 9 | rio: 10 | httpsPort: 443 11 | httpPort: 80 12 | serviceCidr: "10.43.0.1/16" 13 | installMode: "ingress" 14 | # Service Mesh Mode 15 | smMode: "linkerd" 16 | env: 17 | # - name: RIO_DEBUG 18 | # value: "false" 19 | # - name: IP_ADDRESSES 20 | # value: "" 21 | # - name: DISABLE_FEATURES 22 | # value: "" 23 | # - name: HTTP_PROXY 24 | # value: "" 25 | # - name: INSTALL_MODE 26 | # value: "" 27 | -------------------------------------------------------------------------------- /user-cluster/ssh.tf: -------------------------------------------------------------------------------- 1 | resource "tls_private_key" "ssh" { 2 | algorithm = "RSA" 3 | rsa_bits = 4096 4 | } 5 | 6 | resource "local_file" "private_key" { 7 | sensitive_content = tls_private_key.ssh.private_key_pem 8 | filename = "${path.module}/outputs/id_rsa" 9 | 10 | provisioner "local-exec" { 11 | command = "chmod 0600 ${path.module}/outputs/id_rsa" 12 | } 13 | } 14 | 15 | resource "local_file" "public_key" { 16 | content = tls_private_key.ssh.public_key_openssh 17 | filename = "${path.module}/outputs/id_rsa.pub" 18 | } 19 | 20 | resource "aws_key_pair" "ssh" { 21 | key_name_prefix = local.name 22 | public_key = tls_private_key.ssh.public_key_openssh 23 | } 24 | -------------------------------------------------------------------------------- /user-cluster/cluster-ha.tf: -------------------------------------------------------------------------------- 1 | resource "rancher2_cluster" "user-cluster" { 2 | name = "${local.name}" 3 | description = "Terraform managed RKE cluster" 4 | 5 | rke_config { 6 | # Shows how easy it is to update 7 | # kubernetes_version = "v1.13.9-rancher1-2" 8 | kubernetes_version = "v1.14.5-rancher1-1" 9 | cloud_provider { 10 | name = "aws" 11 | } 12 | 13 | services { 14 | etcd { 15 | backup_config { 16 | enabled = true 17 | interval_hours = 6 18 | retention = 12 19 | 20 | s3_backup_config { 21 | access_key = data.terraform_remote_state.server.outputs.etcd_backup_user_key 22 | bucket_name = data.terraform_remote_state.server.outputs.etcd_backup_s3_bucket_id 23 | endpoint = "s3.us-west-2.amazonaws.com" 24 | region = "us-west-2" 25 | folder = local.name 26 | secret_key = data.terraform_remote_state.server.outputs.etcd_backup_user_secret 27 | } 28 | } 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /user-cluster/files/cloud-config.yaml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | ssh_authorized_keys: 3 | - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC06Qvs+Y9JiyOTeYNGAN/Ukq7SmeCTr7EreD1K8Lwu5VuOmo+SBZh685tNTEGV044HgFvGEOBVreDlO2ArYuwHjUBGnpQGV8/abjoeLrmZBdREAUzBQ1h2GFE/WssKUfum81cnigRK1J3tWP7emq/Y2h/Zw5F09yiCIlXMBX2auKWUCXqwG3xKTi1NVSF9N6BGyFolrAR0LZJ6k7UBXPRc/QDTclI427gSJNbnmn8LVym6YxacV/V9Y7s23iR5zYbhLPe9VJWYNk1brVvfUVb3mILVVYz76KGEq8SHdWlPQPCOp+fSJ+PezDRklnex/MmvhNrBOmMSNcpj7wSLA3hD wmaxwell@wmaxwell-laptop 4 | - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN5O7k6gRYCU7YPkCH6dyXVW10izMAkDAQtQxNxdRE22 drpebcak 5 | runcmd: 6 | - apt-get update 7 | - apt-get install -y apt-transport-https jq software-properties-common curl 8 | - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 9 | - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 10 | - apt-get update 11 | - apt-get -y install docker-ce=5:18.09.2~3-0~ubuntu-bionic 12 | - usermod -G docker -a ubuntu 13 | - ${registration_command} --internal-address $(curl -s http://169.254.169.254/latest/meta-data/local-ipv4) 14 | -------------------------------------------------------------------------------- /install-app/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "remote" { 3 | organization = "drpebcak" 4 | workspaces { 5 | name = "rancher-as-code_install-app" 6 | } 7 | } 8 | } 9 | 10 | resource "rancher2_catalog" "demo" { 11 | name = "rio-catalog" 12 | url = "https://github.com/drpebcak/rancher-as-code.git" 13 | branch = "master" 14 | description = "Rancher-style helm repository with charts for installing Rio" 15 | } 16 | 17 | data "rancher2_project" "system" { 18 | cluster_id = data.terraform_remote_state.cluster.outputs.cluster_id 19 | name = "System" 20 | } 21 | 22 | resource "rancher2_namespace" "rio-system" { 23 | name = "rio-system" 24 | description = "Namespace for Rio components" 25 | project_id = data.rancher2_project.system.id 26 | } 27 | 28 | resource "rancher2_app" "rio" { 29 | catalog_name = "rio-catalog" 30 | name = "rio" 31 | project_id = data.rancher2_project.system.id 32 | target_namespace = rancher2_namespace.rio-system.name 33 | template_name = "rio" 34 | template_version = "0.0.1" 35 | depends_on = [rancher2_catalog.demo] 36 | values_yaml = <