Aws EC2 + Aws Cli + Terraform

1 什么是 Terraform?

Terraform 是由 HashiCorp 创建的"基础架构即代码"(Infrastructure-as-Code,IaC)开源工具。Terraform 的配置语言是 HashiCorp Configuration Language(HCL),用来替代更加冗长的 JSON 和 XML 等配置语言。Terraform通过tf配置文件管理Aws云资源(ec2,s3,lambda等各种资源)。

2 EC2 Linux安装Terraform

bash 复制代码
$ sudo yum install -y yum-utils shadow-utils
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
$ sudo yum -y install terraform

$ terraform -version
Terraform v1.8.3
on linux_amd64

3 Terraform

  1. 创建秘钥

s3_user有s3的权限策略

点击下一步,再点击创建访问秘钥

访问秘钥access_key,秘密访问秘钥secret_key

  1. tf文件
bash 复制代码
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "us-east-2"
  access_key  = "AKIAVRUVxxxxxxxxxx"
  secret_key   = "S1sU31BBxxxxxxxxxxxxxxxxxxxxxxxx"
}

resource "aws_s3_bucket" "test" {
  bucket = "tf-bucket"
}

官方文档:Terraform Registry

  1. 执行
bash 复制代码
$ terraform init
$ terraform plan
$ terraform apply

生成是tf-bucket的s3的bucket

相关推荐
主机哥哥20 小时前
还不会部署OpenClaw?阿里云推出五种OpenClaw快速部署方案
阿里云·云计算
Re.不晚1 天前
可视化大数据——淘宝母婴购物数据【含详细代码】
大数据·阿里云·云计算
zhougl9961 天前
云计算超详细介绍
云计算
brucelee1861 天前
创建AWS ElastiCache Redis
redis·云计算·aws
AI_56781 天前
Terraform多环境部署:模块化配置一次搞定
云原生·terraform
DeepFlow 零侵扰全栈可观测1 天前
使用 eBPF 零代码修改绘制全景应用拓扑
java·前端·网络·分布式·微服务·云原生·云计算
不惑_2 天前
通俗理解记忆网络(Memory Network)——从0到1彻底掌握End-to-End MemNN
人工智能·架构·云计算·transformer
人间打气筒(Ada)2 天前
代码版本控制系统变更
git·svn·云计算·gitlab·ci·cd·代码变更
xfan_me2 天前
2025年最受欢迎API接口:重塑数字世界的核心力量
大数据·人工智能·云计算
了不起的云计算V2 天前
亿万级春运大考:中航信国产技术栈扛起民航核心系统
服务器·搜索引擎·云计算