I'd like to use this SDK to programmatically generate ARM templates, but not send requests to the Azure api. Similar to the Troposphere for CloudFormation. Is this possible?
@robbyt Technically it is possible but I don't this I have seen anyone generating templates from Azure language SDKs. People mostly author them by hand. Do you have an example?
@ahmetalpbalkan thanks for the quick response!
JSON, (and XML) is a file format that is best when humans don't have to write it. :)
For example, when working with Troposphere, this bit of Python code: https://github.com/cloudtools/troposphere/blob/master/examples/EC2InstanceSample.py will generate this CloudFormation template: https://github.com/cloudtools/troposphere/blob/master/tests/examples_output/EC2InstanceSample.template
It would be really great to use this Go SDK to create objects that could be marshaled out to JSON files, so that we can create and distribute reusable templates.
@robbyt I see. Yes, this is technically possible. Our packages have models with json field name tags and API versions for resources, you should be able to marshal the topology into an ARM template JSON.
Great!
Is it possible to give me a simple example? I'm happy to help write some docs for this project if you can give me a bit of guidance.
You can find example templates at https://github.com/Azure/azure-quickstart-templates
The model classes are named models.go under each package here: https://github.com/Azure/azure-sdk-for-go/tree/master/arm
You will just create the JSON object for the template in Go, it'll have parameters, resources fields etc. "resources" will be an array of
type TemplateResource struct {
Type, Name, Location, ApiVersion string `json:tags here for each field`
Properties interface{} `json:"properties"`
}
and you will just json.Marshal(object) then you should have a template.
@robbyt I strongly suggest getting familiar with ARM template language and actually writing your template manually by hand first. Go part will be trivial.
@ahmetalpbalkan thank you for the example, and recommendation.
I've written a lot of CloudFormation code for AWS- are you familiar? Do you think it's conceptually similar to ARM templates? (obviously, with different resource primitives)
@robbyt from what I can see, they're really similar. I suggest going through 101-* 201-* examples in the quickstart repo. There are also docs available on azure.com.
@robbyt closing this as I'm assuming this answers your question.
@ahmetalpbalkan thanks, it was super helpful :+1:
Robbyt did this ever get completed? I would also like to use trophosphere with Azure.
Most helpful comment
Robbyt did this ever get completed? I would also like to use trophosphere with Azure.