Terraform GitHub Actions 项目教程

Terraform GitHub Actions 项目教程

terraform-github-actionsA reference implementation of using GitHub Actions to deploy infrastructure to Azure using Terraform项目地址:https://gitcode.com/gh_mirrors/terr/terraform-github-actions

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

.
├── README.md
├── action.yml
├── entrypoint.sh
├── main.tf
├── outputs.tf
├── variables.tf
└── versions.tf
  • README.md: 项目说明文档,包含项目的基本信息和使用指南。
  • action.yml: GitHub Actions 的配置文件,定义了动作的输入、输出和运行步骤。
  • entrypoint.sh: 项目的启动脚本,负责执行 Terraform 命令。
  • main.tf: Terraform 的主配置文件,定义了基础设施的资源。
  • outputs.tf: Terraform 的输出配置文件,定义了资源的输出值。
  • variables.tf: Terraform 的变量配置文件,定义了可用的变量。
  • versions.tf: Terraform 的版本配置文件,定义了所需的 Terraform 版本和提供者版本。

2. 项目的启动文件介绍

entrypoint.sh

entrypoint.sh 是一个 Bash 脚本,作为项目的启动文件。它负责执行 Terraform 命令,并处理相关的输入和输出。以下是 entrypoint.sh 的基本内容:

#!/bin/bash

# 设置 Terraform 命令
terraform init
terraform plan
terraform apply -auto-approve

该脚本首先初始化 Terraform 环境,然后生成执行计划,并自动应用该计划。

3. 项目的配置文件介绍

action.yml

action.yml 是 GitHub Actions 的配置文件,定义了动作的输入、输出和运行步骤。以下是 action.yml 的基本内容:

name: 'Terraform GitHub Actions'
description: 'Run Terraform commands in GitHub Actions'
inputs:
  terraform_version:
    description: 'Terraform version to use'
    required: false
    default: 'latest'
runs:
  using: 'docker'
  image: 'Dockerfile'
  args:
    - ${{ inputs.terraform_version }}

该文件定义了一个名为 Terraform GitHub Actions 的动作,并接受一个可选的输入参数 terraform_version,默认值为 latest

main.tf

main.tf 是 Terraform 的主配置文件,定义了基础设施的资源。以下是 main.tf 的基本内容:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

该文件定义了一个 Azure 资源提供者,并创建了一个名为 example-resources 的资源组。

variables.tf

variables.tf 是 Terraform 的变量配置文件,定义了可用的变量。以下是 variables.tf 的基本内容:

variable "location" {
  description = "The Azure region to deploy resources"
  default     = "West Europe"
}

该文件定义了一个名为 location 的变量,默认值为 West Europe

outputs.tf

outputs.tf 是 Terraform 的输出配置文件,定义了资源的输出值。以下是 outputs.tf 的基本内容:

output "resource_group_name" {
  description = "The name of the resource group"
  value       = azurerm_resource_group.example.name
}

该文件定义了一个名为 resource_group_name 的输出,值为创建的资源组的名称。

versions.tf

versions.tf 是 Terraform 的版本配置文件,定义了所需的 Terraform 版本和提供者版本。以下是 versions.tf 的基本内容:

terraform {
  required_version = ">= 0.12"

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 2.0"
    }
  }
}

该文件定义了所需的 Terraform 版本为 >= 0.12,并指定了 AzureRM 提供者的版本为 `~> 2.0

terraform-github-actionsA reference implementation of using GitHub Actions to deploy infrastructure to Azure using Terraform项目地址:https://gitcode.com/gh_mirrors/terr/terraform-github-actions

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

孔祯拓Belinda

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

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

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

打赏作者

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

抵扣说明:

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

余额充值