Last active
August 3, 2017 18:46
-
-
Save krisnova/53525fe745d6f5c50f4eccc2dac8f0f1 to your computer and use it in GitHub Desktop.
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
package main | |
import "io/ioutil" | |
type AzureBlobber interface { | |
Render() ([]byte, []byte, error) | |
} | |
type MyAzureBlob struct { | |
Paramters map[string]interface{} | |
Variables map[string]interface{} | |
Resources map[string]interface{} | |
} | |
func NewMyAzureBlob() *MyAzureBlob { | |
return &MyAzureBlob{} | |
} | |
func (b *MyAzureBlob) Render() ([]byte, []byte, error) { | |
// Logic to render the ARM template and params file | |
return []byte(""), []byte(""), nil | |
} | |
func (b *MyAzureBlob) WithManagedDisks(param1 int, param2 string) { | |
// Logic to add managed disks to the azure blob | |
} | |
func (b *MyAzureBlob) WithJumpBox(vmSize string, count int) { | |
// Logic to add a jumpbox to the azure blob | |
} | |
func main() { | |
var blob AzureBlobber | |
style := 1 | |
// Logic to select a style of blob | |
switch style{ | |
case 1: | |
// This should return an error in real life | |
blob = buildBlobStyle1() | |
case 2: | |
// This should return an error in real life | |
blob = buildBlobStyle2() | |
} | |
// The blob has been built, let's render | |
template, params, err := blob.Render() | |
if err != nil { | |
//darn | |
} | |
// Write to disk | |
ioutil.WriteFile("azuredeploy.json", template, 0644) | |
ioutil.WriteFile("azuredeploy.parameters.json", params, 0644) | |
} | |
func buildBlobStyle1() AzureBlobber { | |
blob := NewMyAzureBlob() | |
blob.WithJumpBox("small", 1) | |
return blob | |
} | |
func buildBlobStyle2() AzureBlobber { | |
blob := NewMyAzureBlob() | |
blob.WithJumpBox("large", 10) | |
blob.WithManagedDisks(1, "something") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment