Terraform AWS Pricing 模块使用教程

Terraform AWS Pricing 模块使用教程

terraform-aws-pricing Terraform module which calculates price of AWS infrastructure (from Terraform state and plan) 🇺🇦 terraform-aws-pricing 项目地址: https://gitcode.com/gh_mirrors/te/terraform-aws-pricing

1. 项目的目录结构及介绍

terraform-aws-pricing/
├── examples/
│   └── complete/
│       └── main.tf
├── modules/
│   └── pricing/
│       ├── main.tf
│       ├── variables.tf
│       └── outputs.tf
├── README.md
└── LICENSE

目录结构介绍

  • examples/: 包含示例配置文件,展示了如何使用 terraform-aws-pricing 模块。

    • complete/: 一个完整的示例,展示了如何配置和使用该模块。
      • main.tf: 示例的主要配置文件,展示了如何调用 terraform-aws-pricing 模块。
  • modules/: 包含模块的核心代码。

    • pricing/: 定价模块的核心代码。
      • main.tf: 模块的主要逻辑文件。
      • variables.tf: 定义了模块的输入变量。
      • outputs.tf: 定义了模块的输出值。
  • README.md: 项目的介绍和使用说明。

  • LICENSE: 项目的开源许可证。

2. 项目的启动文件介绍

examples/complete/main.tf

provider "aws" {
  region = "us-east-1"
}

module "pricing" {
  source = "../../../modules/pricing"
  debug_output = true
  aws_default_region = "eu-west-1"
  content = jsondecode(data.local_file.local_plan.content)
  resources = {
    "aws_instance.this#3" = [
      {
        instanceType = "c5.xlarge"
        location = "eu-west-2"
      }
    ]
    "aws_instance.this2" = [
      {
        instanceType = "c4.xlarge"
        location = "eu-central-1"
      }
    ]
  }
}

############################
# Terraform plan (as JSON)
############################
data "local_file" "local_plan" {
  filename = "./fixtures/etc/ec2/terraform.tfstate"
}

启动文件介绍

  • provider "aws": 配置 AWS 提供者,指定区域为 us-east-1
  • module "pricing": 调用 terraform-aws-pricing 模块,配置了调试输出、默认区域、内容和资源。
    • source: 指定模块的源路径。
    • debug_output: 启用调试输出。
    • aws_default_region: 设置默认的 AWS 区域。
    • content: 从本地文件中读取 Terraform 计划的内容。
    • resources: 定义了 AWS 实例的类型和位置。
  • data "local_file" "local_plan": 从本地文件中读取 Terraform 计划的内容。

3. 项目的配置文件介绍

modules/pricing/main.tf

# 模块的主要逻辑文件
# 这里包含了计算 AWS 基础设施成本的逻辑

modules/pricing/variables.tf

# 定义了模块的输入变量
# 例如:debug_output, aws_default_region, content, resources

modules/pricing/outputs.tf

# 定义了模块的输出值
# 例如:计算出的 AWS 基础设施成本

配置文件介绍

  • main.tf: 模块的主要逻辑文件,包含了计算 AWS 基础设施成本的逻辑。
  • variables.tf: 定义了模块的输入变量,如 debug_output, aws_default_region, content, resources 等。
  • outputs.tf: 定义了模块的输出值,如计算出的 AWS 基础设施成本。

通过以上配置文件,用户可以根据自己的需求配置和使用 terraform-aws-pricing 模块,计算 AWS 基础设施的成本。

terraform-aws-pricing Terraform module which calculates price of AWS infrastructure (from Terraform state and plan) 🇺🇦 terraform-aws-pricing 项目地址: https://gitcode.com/gh_mirrors/te/terraform-aws-pricing

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

廉妤秋Swift

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值