-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from accurics/kubernetes-support
initial kubernetes support
- Loading branch information
Showing
146 changed files
with
3,465 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright (C) 2020 Accurics, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
table := []struct { | ||
name string | ||
iacType string | ||
iacVersion string | ||
cloudType string | ||
iacFilePath string | ||
iacDirPath string | ||
configFile string | ||
configOnly bool | ||
stdOut string | ||
want string | ||
wantErr error | ||
}{ | ||
{ | ||
name: "normal terraform run", | ||
cloudType: "terraform", | ||
iacDirPath: "testdata/run-test", | ||
}, | ||
{ | ||
name: "normal k8s run", | ||
cloudType: "k8s", | ||
iacDirPath: "testdata/run-test", | ||
}, | ||
{ | ||
name: "config-only flag terraform", | ||
cloudType: "terraform", | ||
iacFilePath: "testdata/run-test/config-only.tf", | ||
configOnly: true, | ||
}, | ||
{ | ||
name: "config-only flag k8s", | ||
cloudType: "k8s", | ||
iacFilePath: "testdata/run-test/config-only.yaml", | ||
configOnly: true, | ||
}, | ||
} | ||
|
||
for _, tt := range table { | ||
t.Run(tt.name, func(t *testing.T) { | ||
Run(tt.iacType, tt.iacVersion, tt.cloudType, tt.iacFilePath, tt.iacDirPath, tt.configFile, "", "", tt.configOnly) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resource "aws_subnet" "default" { | ||
vpc_id = aws_vpc.default.id | ||
cidr_block = "10.0.1.0/24" | ||
map_public_ip_on_launch = true | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: accurics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Specify the provider and access details | ||
provider "aws" { | ||
region = "var.aws_region" | ||
} | ||
|
||
provider "kubernetes" { | ||
} | ||
|
||
# Create a VPC to launch our instances into | ||
resource "aws_vpc" "acme_root" { | ||
cidr_block = "10.0.0.0/16" | ||
tags = { | ||
Name = "acme_root" | ||
} | ||
} | ||
|
||
# Create an internet gateway to give our subnet access to the outside world | ||
resource "aws_internet_gateway" "acme_root" { | ||
vpc_id = "aws_vpc.acme_root.id" | ||
tags = { | ||
Name = "acme_root" | ||
} | ||
} | ||
|
||
# Grant the VPC internet access on its main route table | ||
resource "aws_route" "acme_root" { | ||
route_table_id = "aws_vpc.acme_root.main_route_table_id" | ||
destination_cidr_block = "0.0.0.0/0" | ||
gateway_id = "aws_internet_gateway.acme_root.id" | ||
} | ||
|
||
# Create a subnet to launch our instances into | ||
resource "aws_subnet" "acme_web" { | ||
vpc_id = "aws_vpc.acme_root.id" | ||
cidr_block = "10.0.1.0/24" | ||
map_public_ip_on_launch = true | ||
tags = { | ||
Name = "acme_web" | ||
} | ||
} | ||
|
||
resource "aws_key_pair" "auth" { | ||
key_name = "var.key_name" | ||
public_key = "file(var.public_key_path)" | ||
} | ||
|
||
# resource "aws_s3_bucket" "acme_main" { | ||
# bucket = "main-bucket" | ||
# acl = "private" | ||
# } | ||
|
||
resource "aws_ecr_repository" "scanOnPushDisabled" { | ||
name = "test" | ||
|
||
image_scanning_configuration { | ||
scan_on_push = false | ||
} | ||
} | ||
|
||
resource "aws_ecr_repository_policy" "ecrRepoIsPublic" { | ||
repository = "some-Repo-Name" | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2008-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "new policy", | ||
"Effect": "Allow", | ||
"Principal": "*", | ||
"Action": ["*"] | ||
} | ||
] | ||
} | ||
EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: myapp-pod | ||
labels: | ||
app: myapp | ||
test: someupdate | ||
test2: someupdate3 | ||
spec: | ||
containers: | ||
- name: myapp-container | ||
image: busybox | ||
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600'] | ||
securityContext: | ||
allowPrivilegeEscalation: true | ||
--- | ||
apiVersion: apps/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: myapp-deployment2 | ||
labels: | ||
app: myapp | ||
test: someupdate | ||
test2: someupdate3 | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: myapp-container2 | ||
image: busybox | ||
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600'] | ||
securityContext: | ||
allowPrivilegeEscalation: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
variable "public_key_path" { | ||
description = <<DESCRIPTION | ||
Path to the SSH public key to be used for authentication. | ||
Ensure this keypair is added to your local SSH agent so provisioners can | ||
connect. | ||
Example: ~/.ssh/terraform.pub | ||
DESCRIPTION | ||
default = "terraform-poc01.pub" | ||
} | ||
|
||
variable "key_name" { | ||
description = "Desired name of AWS key pair" | ||
default = "terraform-poc01" | ||
} | ||
|
||
variable "aws_region" { | ||
description = "AWS region to launch servers." | ||
default = "ap-south-1" | ||
} | ||
|
||
# Ubuntu Precise 12.04 LTS (x64) | ||
variable "aws_amis" { | ||
default = { | ||
eu-west-1 = "ami-674cbc1e" | ||
us-east-1 = "ami-1d4e7a66" | ||
us-west-1 = "ami-969ab1f6" | ||
us-west-2 = "ami-8803e0f0" | ||
ap-south-1 = "ami-0123b531fc646552f" | ||
} | ||
} | ||
|
||
variable "sample" { | ||
default = "demo" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
### | ||
# Our default security group to access | ||
# the instances over SSH and HTTP | ||
resource "aws_security_group" "acme_web" { | ||
name = "acme_web" | ||
description = "Used in the terraform" | ||
vpc_id = "aws_vpc.acme_root.id" | ||
|
||
tags = { | ||
Name = "acme_web" | ||
} | ||
|
||
# SSH access from anywhere | ||
ingress { | ||
from_port = 22 | ||
to_port = 22 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
|
||
# HTTP access from the VPC | ||
ingress { | ||
from_port = 80 | ||
to_port = 80 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
# outbound internet access | ||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
} | ||
|
||
resource "aws_instance" "acem_web" { | ||
# The connection block tells our provisioner how to | ||
# communicate with the resource (instance) | ||
# connection { | ||
# # The default username for our AMI | ||
# user = "ubuntu" | ||
# host = "acme" | ||
# # The connection will use the local SSH agent for authentication. | ||
# } | ||
|
||
tags = { | ||
Name = "acem_web" | ||
} | ||
|
||
instance_type = "t2.micro" | ||
|
||
# Lookup the correct AMI based on the region | ||
# we specified | ||
ami = "lookup(var.aws_amis, var.aws_region)" | ||
|
||
# The name of our SSH keypair we created above. | ||
key_name = "aws_key_pair.auth.id" | ||
|
||
# Our Security group to allow HTTP and SSH access | ||
vpc_security_group_ids = ["aws_security_group.acme_web.id"] | ||
|
||
# We're going to launch into the same subnet as our ELB. In a production | ||
# environment it's more common to have a separate private subnet for | ||
# backend instances. | ||
subnet_id = "aws_subnet.acme_web.id" | ||
|
||
# We run a remote provisioner on the instance after creating it. | ||
# In this case, we just install nginx and start it. By default, | ||
# this should be on port 80 | ||
# provisioner "remote-exec" { | ||
# inline = [ | ||
# "sudo apt-get -y update", | ||
# "sudo apt-get -y install nginx", | ||
# "sudo service nginx start", | ||
# ] | ||
# } | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.