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

相关推荐
cool320012 小时前
Kubernetes基础入门教程
容器·云计算·k8s
TG_yunshuguoji13 小时前
阿里云代理商: 阿里云部署OpenClaw 个性化配置指南 3 大场景模板详解
服务器·阿里云·云计算·openclaw
翼龙云_cloud18 小时前
阿里云代理商:阿里云部署 OpenClaw 常见问题排查手册
服务器·人工智能·阿里云·云计算·openclaw
TG_yunshuguoji20 小时前
腾讯云代理商:腾讯云 × OpenClaw 三步极速接入 iMessage 实现跨设备智能控制
服务器·云计算·腾讯云·openclaw
云飞云共享云桌面20 小时前
精密机械制造工厂10个SolidWorks研发共享一台服务器设计办公
运维·服务器·网络·云计算·电脑
147API1 天前
从零开始上手 AWS:架构设计、成本优化与避坑指南
云计算·claude·aws
gaize12131 天前
腾讯云蜂驰型 BF1
云计算·腾讯云
2201_756206341 天前
AT指令测试ML407模块连接阿里云平台发生数据总结
阿里云·云计算
林九生1 天前
【Claude Code】Claude Code 接入阿里云百炼 Coding Plan 完整配置教程(Linux版)
linux·阿里云·云计算
翼龙云_cloud2 天前
阿里云渠道商:百炼模型选型指南 性能与成本全解析
人工智能·阿里云·云计算