Last active
July 20, 2017 15:58
-
-
Save olivoil/1348a7e78db264c5e6ca876140fb1948 to your computer and use it in GitHub Desktop.
example of what an `up` configuration file would look like in HCL
This file contains hidden or 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
name = "api" | |
description = "Some API for whatever" | |
hooks { | |
build = "make build" | |
clean = "make clean" | |
} | |
environment { | |
BAR = "here" | |
FOO = "here" | |
} | |
cors { | |
allowed_origins = ["example.com"] | |
allowed_methods = ["GET"] | |
max_age = 123123 | |
} | |
lambda { | |
memory = 1024 | |
timeout = 5 | |
} | |
dns { | |
zone "apex.sh" { | |
record "blog.apex.sh" { | |
type = "CNAME" | |
ttl = 300 | |
} | |
} | |
} |
This file contains hidden or 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
{ | |
"name": "api", | |
"description": "Some API for whatever", | |
"hooks": { | |
"build": "make build", | |
"clean": "make clean" | |
}, | |
"environment": { | |
"BAR": "here", | |
"FOO": "here" | |
}, | |
"cors": { | |
"allowed_origins": null, | |
"allowed_methods": null, | |
"max_age": 0 | |
}, | |
"lambda": { | |
"memory": 1024, | |
"timeout": 5 | |
}, | |
"dns": { | |
"zone": { | |
"apex.sh": { | |
"record": { | |
"blog.apex.sh": { | |
"type": "CNAME", | |
"ttl": 300 | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"github.com/hashicorp/hcl" | |
) | |
type Config struct { | |
Name string `json:"name"` | |
Description string `json:"description"` | |
Hooks struct { | |
Build string `json:"build"` | |
Clean string `json:"clean"` | |
} `json:"hooks"` | |
Environment map[string]string `json:"environment"` | |
Cors struct { | |
AllowedOrigins []string `json:"allowed_origins"` | |
AllowedMethods []string `json:"allowed_methods"` | |
MaxAge int `json:"max_age"` | |
} `json:"cors"` | |
Lambda struct { | |
Memory int `json:"memory"` | |
Timeout int `json:"timeout"` | |
} `json:"lambda"` | |
Dns struct { | |
Zone map[string]struct { | |
Record map[string]struct { | |
Type string `json:"type"` | |
Ttl int `json:"ttl"` | |
} `json:"record"` | |
} `json:"zone"` | |
} `json:"dns"` | |
} | |
func check(e error) { | |
if e != nil { | |
panic(e) | |
} | |
} | |
func main() { | |
content, err := ioutil.ReadFile("./config.hcl") | |
check(err) | |
config := Config{} | |
err = hcl.Unmarshal(content, &config) | |
check(err) | |
out, err := json.MarshalIndent(config, "", " ") | |
check(err) | |
fmt.Printf("json equivalent:\n%v\n", string(out)) | |
err = ioutil.WriteFile("./config.json", out, 0644) | |
check(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment