aws-cloudformation - 模板(即基础设施即代码)相对于 API 调用的优势

标签 aws-cloudformation azure-resource-manager google-deployment-manager infrastructure-as-code

我正在尝试设置一个模块来在云中部署资源(可以是任何云提供商)。我没有看到使用模板(即部署管理器)相对于直接 API 调用的优势:

使用模板创建虚拟机:

# 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

使用 API 调用创建 VM:

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)

有人可以向我解释一下使用模板有什么好处吗?

最佳答案

可读性\易于使用\为您处理身份验证\无需成为编码员\等。优点可能有很多,这实际上取决于你如何看待它。这取决于你的背景\你使用的工具。

专门为您使用 python 可能会更有利。

关于aws-cloudformation - 模板(即基础设施即代码)相对于 API 调用的优势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57960689/

相关文章:

amazon-web-services - AWS cloudform 删除失败

aws-lambda - 将预训练模型从 CloudFormation 部署到 SageMaker Endpoint

azure - 二头肌模板在存储帐户中创建容器

google-deployment-manager - 常见的 RESOURCE_EXHAUSTED 错误

python - 部署管理器 : Not able to expose output through python template

amazon-web-services - AWS CloudFormation - 将新证书添加到现有监听器

aws-cloudformation - 由于未定义的资源策略,IAM 嵌套堆栈无法完成

image - Azure VM 自定义操作系统镜像 ARM 模板部署

azure - 如何使用 Azure 资源管理器模板部署 Azure Function(及其代码)?

google-cloud-platform - 部署管理器更新错误 : Deployment in preview must not have a target with UPDATE