Skip to content

Commit

Permalink
removing coreos support, adding file upload directive to host YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Levinson committed Oct 1, 2017
1 parent e1718fa commit 0654075
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 49 deletions.
6 changes: 3 additions & 3 deletions competition/bindata.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions competition/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"

Expand Down Expand Up @@ -31,6 +33,8 @@ type Dependency struct {
Network string `yaml:"network"`
}

type RemoteFiles map[string]string

type Host struct {
Hostname string `yaml:"hostname"`
OS string `yaml:"os"`
Expand All @@ -45,10 +49,24 @@ type Host struct {
UserGroups []string `yaml:"user_groups"`
DNSEntries []DNSEntry `yaml:"dns_entries"`
Dependencies []Dependency `yaml:"dependencies"`
Files RemoteFiles `yaml:"files"`
Vars `yaml:"variables"`
Network `yaml:"-"`
}

func (h *Host) UploadFiles() map[string]string {
newFiles := map[string]string{}
for file, path := range h.Files {
fileName := filepath.Join(GetHome(), "files", file)
if _, err := os.Stat(fileName); os.IsNotExist(err) {
LogError(fmt.Sprintf("File not found: file=%s host=%s", fileName, h.Hostname))
continue
}
newFiles[fileName] = path
}
return newFiles
}

func (h *Host) ValidTCPPorts() []string {
ports := []string{}
for _, port := range h.TCPPorts {
Expand Down
9 changes: 0 additions & 9 deletions templates/amis.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@
},
"username": "administrator"
},
{
"os": "coreos",
"regions": {
"us-east-1": "ami-7500100e",
"us-east-2": "ami-c77351a2",
"us-west-2": "ami-5e6f9b26"
},
"username": "core"
},
{
"os": "kali",
"regions": {
Expand Down
2 changes: 1 addition & 1 deletion templates/host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ hostname: {{ .Hostname }}
#########################################################
# Operating System (Required for proper Conn Types)
# ** Case Sensitive **
# Valid: ubuntu, centos, coreos, w2k16, w2k16sql, w2k12
# Valid: ubuntu, centos, kali, w2k16, w2k16sql, w2k12
os: ubuntu

#########################################################
Expand Down
96 changes: 61 additions & 35 deletions templates/infra.tf
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,18 @@ resource "aws_instance" "{{ $id }}_{{ $network.Subdomain }}_{{ $hostname }}" {
password = "{{ $.Competition.RootPassword }}"
}

{{ $fileUploads := $host.UploadFiles }}
{{ $fileUploadCount := len $fileUploads }}
{{ if gt $fileUploadCount 0 }}
{{ range $localFile, $remoteFile := $fileUploads }}
provisioner "file" {
source = "{{ $localFile }}"
destination = "{{ $remoteFile }}"
}
{{ end }}
{{ end }}


{{ $scriptCount := len $host.Scripts }}
{{ if gt $scriptCount 0 }}

Expand Down Expand Up @@ -536,6 +548,17 @@ resource "aws_instance" "{{ $id }}_{{ $network.Subdomain }}_{{ $hostname }}" {
password = "{{ $.Competition.RootPassword }}"
}

{{ $fileUploads := $host.UploadFiles }}
{{ $fileUploadCount := len $fileUploads }}
{{ if gt $fileUploadCount 0 }}
{{ range $localFile, $remoteFile := $fileUploads }}
provisioner "file" {
source = "{{ $localFile }}"
destination = "{{ $remoteFile }}"
}
{{ end }}
{{ end }}

{{ $scriptCount := len $host.Scripts }}
{{ if gt $scriptCount 0 }}

Expand Down Expand Up @@ -577,6 +600,17 @@ resource "aws_instance" "{{ $id }}_{{ $network.Subdomain }}_{{ $hostname }}" {
password = "{{ $.Competition.RootPassword }}"
}

{{ $fileUploads := $host.UploadFiles }}
{{ $fileUploadCount := len $fileUploads }}
{{ if gt $fileUploadCount 0 }}
{{ range $localFile, $remoteFile := $fileUploads }}
provisioner "file" {
source = "{{ $localFile }}"
destination = "{{ $remoteFile }}"
}
{{ end }}
{{ end }}

{{ $scriptCount := len $host.Scripts }}
{{ if gt $scriptCount 0 }}

Expand Down Expand Up @@ -618,6 +652,17 @@ resource "aws_instance" "{{ $id }}_{{ $network.Subdomain }}_{{ $hostname }}" {
private_key = "${file("{{ $.Competition.SSHPrivateKeyPath }}")}"
}

{{ $fileUploads := $host.UploadFiles }}
{{ $fileUploadCount := len $fileUploads }}
{{ if gt $fileUploadCount 0 }}
{{ range $localFile, $remoteFile := $fileUploads }}
provisioner "file" {
source = "{{ $localFile }}"
destination = "{{ $remoteFile }}"
}
{{ end }}
{{ end }}

{{ $scriptCount := len $host.Scripts }}
{{ if gt $scriptCount 0 }}

Expand Down Expand Up @@ -646,45 +691,26 @@ resource "aws_instance" "{{ $id }}_{{ $network.Subdomain }}_{{ $hostname }}" {

user_data = "${file("{{ $scriptPath }}")}"

{{ $scriptCount := len $host.Scripts }}
{{ if gt $scriptCount 0 }}
connection {
type = "ssh"
user = "root"
timeout = "60m"
private_key = "${file("{{ $.Competition.SSHPrivateKeyPath }}")}"
}

{{ range $_, $sname := $host.Scripts }}
{{ $scriptPath := DScript $sname $.Competition $.Environment $i $network $host $hostname }}
{{ if ne $scriptPath "SCRIPT_PARSING_ERROR" }}
provisioner "file" {
source = "{{ $scriptPath }}"
destination = "/tmp/{{ $sname }}"
}
connection {
type = "ssh"
user = "root"
timeout = "60m"
private_key = "${file("{{ $.Competition.SSHPrivateKeyPath }}")}"
}

provisioner "remote-exec" {
inline = [
"chmod +x /tmp/{{ $sname }}",
"/tmp/{{ $sname }}",
"rm -f /tmp/{{ $sname }}",
]
}
{{ end }}
{{ end }}
{{ $fileUploads := $host.UploadFiles }}
{{ $fileUploadCount := len $fileUploads }}
{{ if gt $fileUploadCount 0 }}
{{ range $localFile, $remoteFile := $fileUploads }}
provisioner "file" {
source = "{{ $localFile }}"
destination = "{{ $remoteFile }}"
}
{{ end }}
{{ end }}
{{ end }}

{{ if eq $host.OS "coreos" }}

{{ $scriptCount := len $host.Scripts }}
{{ if gt $scriptCount 0 }}
connection {
type = "ssh"
user = "core"
timeout = "60m"
private_key = "${file("{{ $.Competition.SSHPrivateKeyPath }}")}"
}
{{ if gt $scriptCount 0 }}

{{ range $_, $sname := $host.Scripts }}
{{ $scriptPath := DScript $sname $.Competition $.Environment $i $network $host $hostname }}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main

const Name string = "laforge"
const Version string = "1.0.17"
const Version string = "1.0.18"

0 comments on commit 0654075

Please sign in to comment.