0

I am trying to setup a module to deploy resources in the cloud (it could be any cloud provider). I don't see the advantages of using templates (ie. the deploy manager) over direct API calls :

Creation of VM using a template :

# deployment.yaml
resources:
- type: compute.v1.instance
  name: quickstart-deployment-vm
  properties:
    zone: us-central1-f
    machineType: f1-micro
 ...

# bash command to deploy yaml file
gcloud deployment-manager deployments create vm-deploy --config deployment.yaml

Creation of VM using a API call :

def addInstance(http, listOfHeaders):
  url = "https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/instances"

  body = {
    "name": "quickstart-deployment-vm",
    "zone": " us-central1-f",
    "machineType": "f1-micro",
...
     }]

bodyContentURLEncoded = urllib.urlencode(bodyContent)
http.request(uri=url, method="POST", body=body)

Can someone explain to me what benefits I get using templates?

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
poloC
  • 537
  • 2
  • 6
  • 16

5 Answers5

2

readability\easy of use\authentication handled for you\no need to be a coder\etc. There can be many advantages, it really depends on how you look at it. It depends on your background\tools you use.

It might be more beneficial to use python all the way for you specifically.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
1

It's easier to use templates and you get a lot of builtin functionality such as running a validation on your template to scan for possible security vulnerabilities and similar. You can also easily delete your infra using the same template as you create it. FWIW, I've gone all the way with templates and do as much as I can with templates and in smaller units. It makes it easy to move out a part of the infra or duplicate it to another project, using a pipeline in GitLab to deploy it for example.

Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
  • wat, delete infrastructure with template? – 4c74356b41 Sep 20 '19 at 15:46
  • @4c74356b41 Yes, it works better to "undeploy" from the CLI than deleting it manually https://docs.aws.amazon.com/cli/latest/reference/cloudformation/delete-stack.html – Niklas Rosencrantz Sep 20 '19 at 18:17
  • ah, i was thinking about azure, you cannot do that – 4c74356b41 Sep 20 '19 at 18:25
  • 1
    @4c74356b41 In AWS it happens that a stack gets stuck during delete if we do it from the console and then we must wait 40 minutes for a timeout. We had more success with deleting stacks like we do deploy from the command-line. Notably this very rarely occurs with google cloud when a deployment is almost always just deleted by the press of a button in the ui console. It might be because of how dependencies between "stacks" are handled in AWS and that deployments in our AWS accounts have more dependencies. I open sourced an example how I do it https://gitlab.com/montao/aws-lambda-go-gitlab-sls – Niklas Rosencrantz Sep 20 '19 at 18:30
1

The reason to use templates over API calls is that templates can be used in use cases where a deterministic outcome is required.

Dennis
  • 779
  • 4
  • 14
0

Both Template and API call has its own benefits. There is always a tradeoff between the two options. If you want more flexibility in the deployment, then the API call suits you better. On the other hand, if the security and complete revision is your priority, then Template should be your choice. Details can be found in this online documentation.

Mustafiz
  • 446
  • 2
  • 8
0

When using a template, orchestration of the deployment is handled by the platform. When using API calls (or other imperative approaches) you need to handle orchestration.

bmoore-msft
  • 8,376
  • 20
  • 22