terraform - AWS - 为项目设置全球预算?
问题描述
我正在开发一个 Terraform 项目,为我公司的每位新员工创建、更新或删除 AWS 沙箱。但是,我们希望每个沙盒都有一个固定预算,并且如果可能的话,不能超过该预算。我阅读了 AWS 预算操作,但我不确定将它与我当前的代码集成的最佳方式是什么。
主文件
## this is creating a new project and I would like to set a budget of $50 for this account
resource "aws_organizations_account" "account" {
name = "sandbox"
email = "new-user+sandbox@company.com"
role_name = "myOrganizationRole"
}
解决方案
您需要在新账户中创建aws_budgets_budget和aws_budgets_budget_action资源。要在新帐户中创建资源,您需要通过承担创建的管理角色为该帐户创建提供程序:
provider "aws" {
alias = "sandbox"
region = "us-east-1"
...
// Specify your credentials source, same as you use for the provider you used for the aws_organizations_account resource
...
assume_role {
role_arn = "arn:aws:iam::${aws_organizations_account.account.id}:role/${aws_organizations_account.account.role_name}"
}
}
现在您可以使用该提供程序在新沙盒帐户中创建预算资源(注意provider
输入参数):
resource "aws_budgets_budget" "example" {
provider = aws.sandbox
name = "example"
budget_type = "USAGE"
limit_amount = "10.0"
limit_unit = "dollars"
time_period_start = "2006-01-02_15:04"
time_unit = "MONTHLY"
}
resource "aws_budgets_budget_action" "example" {
provider = aws.sandbox
budget_name = aws_budgets_budget.example.name
...
}
推荐阅读
- node.js - 从nodejs发送时Web客户端未收到404
- wpf - 在 WPF 数据模板中,我错过了什么?数据显示不正确
- android - 如何在本机反应中避免“发送'geolocationDidChange'而没有注册听众”警告?
- python-3.x - 我有一种简单的方法可以将数字分类到不同的范围吗?
- ethereum - 如何创建加密钱包并导入新的自定义 ERC20 代币
- javascript - 从按钮单击ReactJs上的数组中的输入获取值
- c++ - 使用 Octave GNU 访问输入/输出文件
- javascript - componentDidUpdate() 不会随时更新项目
- html - 将纯 html 重定向到 reactjs 页面
- amazon-web-services - 将 wix 域重定向到亚马逊域时的 SSL 问题