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

相关推荐
全云在线allcloudonline1 小时前
江苏阿里云代理商怎么选?现有服务点、南京节点与项目交付
阿里云·云计算·企业上云
全云在线allcloudonline4 小时前
湖北阿里云代理商怎么选?现有服务点、武汉节点与项目交付
阿里云·云计算·企业上云
全云在线allcloudonline4 小时前
陕西阿里云代理商怎么选?现有服务点、西安节点与项目交付
阿里云·云计算·企业上云
搞科研的小刘选手5 小时前
【哈尔滨信息工程学院主办】第五届信息经济、数据建模与云计算国际学术会议(ICIDC 2026)
云计算·数据建模·学术会议·会议推荐·信息经济
xywww1686 小时前
Claude Opus 5 API 接入实战:国内项目上线前的网络、Key、限流和排错清单
大数据·linux·网络·数据库·云计算·aws
AOwhisky1 天前
Linux(CentOS)系统管理入门笔记(第十四期)——计划任务与进程调度管理:atcron 与 nicechrt
linux·运维·笔记·centos·云计算·进程调度·计划任务
冰封之寂2 天前
Docker 资源管理终极指南:CPU、内存与 IO 的精细化控制
linux·运维·服务器·docker·云计算
yiyeguzhou1002 天前
Load/Store 和 Register–memory 架构
性能优化·云计算
AOwhisky2 天前
Linux(CentOS)系统管理入门笔记(第十二期)——系统管理工具与软件包管理(上篇):Cockpit 与 RPM 包管理
linux·运维·笔记·centos·云计算
TMT星球3 天前
IDC报告:阿里云稳居中国混合云软件及服务市场第一
阿里云·云计算