From 99909b1d7cf345b9811c1d35f7d66fe84a3c62ef Mon Sep 17 00:00:00 2001 From: x p k Date: Sun, 2 Aug 2020 19:07:05 +0800 Subject: [PATCH] MOVE: moving to terraform.example repo --- tf-modulised/.gitignore | 4 -- tf-modulised/README.md | 3 - tf-modulised/ec2-ssm/ec2.tf | 14 ---- tf-modulised/ec2-ssm/provider.tf | 10 --- tf-modulised/kubernetes/sshd/.gitignore | 2 - tf-modulised/kubernetes/sshd/nginx-deploy.tf | 66 ------------------- .../kubernetes/sshd/provider.tf-example | 25 ------- tf-modulised/openstack/provider.tf | 9 --- tf-modulised/openstack/vm.tf | 45 ------------- tf-modulised/vpc-subnets/README.md | 13 ---- tf-modulised/vpc-subnets/m.random/main.tf | 17 ----- tf-modulised/vpc-subnets/var-def.tf | 12 ---- tf-modulised/vpc-subnets/vpc.tf | 23 ------- 13 files changed, 243 deletions(-) delete mode 100644 tf-modulised/.gitignore delete mode 100644 tf-modulised/README.md delete mode 100644 tf-modulised/ec2-ssm/ec2.tf delete mode 100644 tf-modulised/ec2-ssm/provider.tf delete mode 100644 tf-modulised/kubernetes/sshd/.gitignore delete mode 100644 tf-modulised/kubernetes/sshd/nginx-deploy.tf delete mode 100644 tf-modulised/kubernetes/sshd/provider.tf-example delete mode 100644 tf-modulised/openstack/provider.tf delete mode 100644 tf-modulised/openstack/vm.tf delete mode 100644 tf-modulised/vpc-subnets/README.md delete mode 100644 tf-modulised/vpc-subnets/m.random/main.tf delete mode 100644 tf-modulised/vpc-subnets/var-def.tf delete mode 100644 tf-modulised/vpc-subnets/vpc.tf diff --git a/tf-modulised/.gitignore b/tf-modulised/.gitignore deleted file mode 100644 index 4c6b761..0000000 --- a/tf-modulised/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.tfstate -*.tfstate.backup -terraform.tfvars -.terraform diff --git a/tf-modulised/README.md b/tf-modulised/README.md deleted file mode 100644 index bf2154e..0000000 --- a/tf-modulised/README.md +++ /dev/null @@ -1,3 +0,0 @@ -With the new terraform, repeative tasks are modulised. Making the code much cleaner. - -See a list of terraform aws modules - https://registry.terraform.io/modules/terraform-aws-modules diff --git a/tf-modulised/ec2-ssm/ec2.tf b/tf-modulised/ec2-ssm/ec2.tf deleted file mode 100644 index 76763f9..0000000 --- a/tf-modulised/ec2-ssm/ec2.tf +++ /dev/null @@ -1,14 +0,0 @@ -resource "aws_instance" "web" { - ami = "ami-49bbfa38" - instance_type = "t3.micro" - key_name = "kfong-aws" - vpc_security_group_ids = ["sg-053612d40f966eec7"] - subnet_id = "subnet-0a4edc273558afaab" - associate_public_ip_address = true - iam_instance_profile = "AmazonSSMRoleForInstancesQuickSetup" - - tags = { - Name = "kf-ssm-test" - ssm-enabled = "yes" - } -} diff --git a/tf-modulised/ec2-ssm/provider.tf b/tf-modulised/ec2-ssm/provider.tf deleted file mode 100644 index 843e184..0000000 --- a/tf-modulised/ec2-ssm/provider.tf +++ /dev/null @@ -1,10 +0,0 @@ -variable "aws_access_key" {} -variable "aws_secret_key" {} -variable "aws_region" {} - -provider "aws" { - access_key = var.aws_access_key - secret_key = var.aws_secret_key - region = var.aws_region - version = ">= 2.28.1" -} diff --git a/tf-modulised/kubernetes/sshd/.gitignore b/tf-modulised/kubernetes/sshd/.gitignore deleted file mode 100644 index a727610..0000000 --- a/tf-modulised/kubernetes/sshd/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*tfstate* -provider.tf diff --git a/tf-modulised/kubernetes/sshd/nginx-deploy.tf b/tf-modulised/kubernetes/sshd/nginx-deploy.tf deleted file mode 100644 index 66bb22a..0000000 --- a/tf-modulised/kubernetes/sshd/nginx-deploy.tf +++ /dev/null @@ -1,66 +0,0 @@ -resource "kubernetes_deployment" "nginx" { - metadata { - name = "scalable-nginx-example" - labels = { - App = "ScalableNginxExample" - } - } - - spec { - replicas = 2 - selector { - match_labels = { - App = "ScalableNginxExample" - } - } - template { - metadata { - labels = { - App = "ScalableNginxExample" - } - } - spec { - container { - image = "nginx:latest" - name = "example" - - port { - container_port = 60080 - } - - resources { - limits { - cpu = "0.5" - memory = "512Mi" - } - requests { - cpu = "250m" - memory = "50Mi" - } - } - } - } - } - } -} - -resource "kubernetes_service" "nginx" { - metadata { - name = "nginx-example" - } - spec { - selector = { - App = kubernetes_deployment.nginx.spec.0.template.0.metadata[0].labels.App - } - port { - port = 60080 - target_port = 60080 - } - - type = "LoadBalancer" - } -} - -output "lb_ip" { - value = kubernetes_service.nginx.load_balancer_ingress[0].ip -} diff --git a/tf-modulised/kubernetes/sshd/provider.tf-example b/tf-modulised/kubernetes/sshd/provider.tf-example deleted file mode 100644 index 9652b5a..0000000 --- a/tf-modulised/kubernetes/sshd/provider.tf-example +++ /dev/null @@ -1,25 +0,0 @@ -variable "kubernetes_client_certificate"{ - type = string - default = "xxx" -} - -variable "kubernetes_client_key"{ - type = string - default = "xxx" -} - -variable "kubernetes_cluster_ca_certificate"{ - type = string - default = "xxx" -} - -provider "kubernetes" { - load_config_file = "false" - - host = "https://192.168.86.51:6443" - - client_certificate = base64decode(var.kubernetes_client_certificate) - client_key = base64decode(var.kubernetes_client_key) - cluster_ca_certificate = base64decode(var.kubernetes_cluster_ca_certificate) -} - diff --git a/tf-modulised/openstack/provider.tf b/tf-modulised/openstack/provider.tf deleted file mode 100644 index 004f90b..0000000 --- a/tf-modulised/openstack/provider.tf +++ /dev/null @@ -1,9 +0,0 @@ -# Configure the OpenStack Provider -provider "openstack" { - user_name = "admin" - tenant_name = "demo" - password = "your-password" - auth_url = "URL-to-keystone" - region = "RegionOne" -} - diff --git a/tf-modulised/openstack/vm.tf b/tf-modulised/openstack/vm.tf deleted file mode 100644 index eb4264e..0000000 --- a/tf-modulised/openstack/vm.tf +++ /dev/null @@ -1,45 +0,0 @@ -resource "openstack_compute_secgroup_v2" "test-sg1" { - name = "test-sg1" - description = "Allow all" - rule { - from_port = -1 - to_port = -1 - ip_protocol = "icmp" - cidr = "0.0.0.0/0" - } - - rule { - from_port = 1 - to_port = 65535 - ip_protocol = "tcp" - cidr = "0.0.0.0/0" - } - - rule { - from_port = 1 - to_port = 65535 - ip_protocol = "udp" - cidr = "0.0.0.0/0" - } -} - -resource "openstack_compute_instance_v2" "tfvm1" { - name = "tfvm1" - flavor_id = "b8159937-a5f9-46fb-97eb-2d59b67cfedd" - key_pair = "opc-key" - security_groups = ["${openstack_compute_secgroup_v2.test-sg1.name}"] - - block_device { - uuid = "871c021d-baef-4010-ba8e-2a900a48f41c" - source_type = "image" - volume_size = 10 - boot_index = 0 - destination_type = "volume" - delete_on_termination = true - } - - network { - name = "shared" - } -} - diff --git a/tf-modulised/vpc-subnets/README.md b/tf-modulised/vpc-subnets/README.md deleted file mode 100644 index 250910e..0000000 --- a/tf-modulised/vpc-subnets/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# terraform.tfvars example -``` -aws_access_key = "..." -aws_secret_key = "..." -aws_region = "ap-east-1" -default-tags = { - "owner" = "KF" - "terraform" = "initial-deployment-only" - "environment" = "demo" - "project" = "project1" - "application" = "network" -} -``` diff --git a/tf-modulised/vpc-subnets/m.random/main.tf b/tf-modulised/vpc-subnets/m.random/main.tf deleted file mode 100644 index 6a4d35d..0000000 --- a/tf-modulised/vpc-subnets/m.random/main.tf +++ /dev/null @@ -1,17 +0,0 @@ -resource "random_string" "string" { - length = 4 - special = false -} - -resource "random_integer" "number" { - min = 1000 - max = 9999 -} - -output "string" { - value = random_string.string.result -} - -output "number" { - value = random_integer.number.result -} diff --git a/tf-modulised/vpc-subnets/var-def.tf b/tf-modulised/vpc-subnets/var-def.tf deleted file mode 100644 index a84511d..0000000 --- a/tf-modulised/vpc-subnets/var-def.tf +++ /dev/null @@ -1,12 +0,0 @@ -variable "aws_access_key" {} -variable "aws_secret_key" {} -variable "aws_region" {} - -provider "aws" { - access_key = var.aws_access_key - secret_key = var.aws_secret_key - region = var.aws_region - version = ">= 2.28.1" -} - -variable "default-tags" {} diff --git a/tf-modulised/vpc-subnets/vpc.tf b/tf-modulised/vpc-subnets/vpc.tf deleted file mode 100644 index c14d9ae..0000000 --- a/tf-modulised/vpc-subnets/vpc.tf +++ /dev/null @@ -1,23 +0,0 @@ -data "aws_availability_zones" "available" {} - -module "random" { - source = "./m.random" -} - -module "vpc" { - source = "terraform-aws-modules/vpc/aws" - version = "2.6.0" - - name = "demo-vpc-${module.random.number}" - cidr = "172.16.0.0/16" - azs = data.aws_availability_zones.available.names - private_subnets = cidrsubnets("172.16.18.0/23", 1, 1) - public_subnets = cidrsubnets("172.16.20.0/23", 1, 1) - enable_nat_gateway = false - single_nat_gateway = true - enable_dns_hostnames = true - - tags = var.default-tags - -} -