尽管默认官方提供了s3 的操作,但是对于开源minio 无法支持,更多的是aws 的s3,社区提供了一个通用
s3 操作的provider(基于minio 的sdk)

环境准备

  • docker-compose 文件
version: "3"
services:
s3:
image: minio/minio
command: server /export
ports:
- "9000:9000"
volumes:
- ./data:/export
- ./config:/root/.minio
environment:
- "MINIO_ACCESS_KEY=dalongdemo"
- "MINIO_SECRET_KEY=dalongdemo"
  • s3 terraform 操作
    添加了依赖处理以及一个简单静态web 页面部署
provider "s3" {
s3_server = "localhost:9000"
s3_access_key = "dalongdemo"
s3_secret_key = "dalongdemo"
s3_api_signature = "v4"
s3_ssl = false
s3_debug = true
} resource "s3_bucket" "bucket_create" {
bucket = "s3page"
} resource "s3_file" "upload_index_page" {
bucket = "s3page"
name = "index.html"
file_path = "./files/index.html"
content_type = "text.html"
debug = true
depends_on = ["s3_bucket.bucket_create"]
} resource "s3_file" "upload_user_js" {
bucket = "s3page"
name = "user.js"
file_path = "./files/user.js"
content_type = "application/javascript"
debug = true
depends_on = ["s3_bucket.bucket_create"] }

部署

  • 插件准备
我测试环境是mac,使用go get 安装provider,然后copy plugin 到tf 定义文件目录,注意需要创建目录
mkdir -p ./.terraform/plugins/darwin_amd64/
./.terraform/plugins/darwin_amd64/
  • init
terraform init
  • 查看plan
terraform plan

效果

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create Terraform will perform the following actions: + s3_bucket.bucket_create
id: <computed>
bucket: "s3page"
debug: "false" + s3_file.upload_index_page
id: <computed>
bucket: "s3page"
content_type: "text.html"
debug: "true"
file_path: "./files/index.html"
name: "index.html" + s3_file.upload_user_js
id: <computed>
bucket: "s3page"
content_type: "application/javascript"
debug: "true"
file_path: "./files/user.js"
name: "user.js" Plan: 3 to add, 0 to change, 0 to destroy. ------------------------------------------------------------------------ Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
  • apply
terraform apply

效果

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create Terraform will perform the following actions: + s3_bucket.bucket_create
id: <computed>
bucket: "s3page"
debug: "false" + s3_file.upload_index_page
id: <computed>
bucket: "s3page"
content_type: "text.html"
debug: "true"
file_path: "./files/index.html"
name: "index.html" + s3_file.upload_user_js
id: <computed>
bucket: "s3page"
content_type: "application/javascript"
debug: "true"
file_path: "./files/user.js"
name: "user.js" Plan: 3 to add, 0 to change, 0 to destroy. Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve. Enter a value: yes s3_bucket.bucket_create: Creating...
bucket: "" => "s3page"
debug: "" => "false"
s3_bucket.bucket_create: Creation complete after 0s
s3_file.upload_index_page: Creating...
bucket: "" => "s3page"
content_type: "" => "text.html"
debug: "" => "true"
file_path: "" => "./files/index.html"
name: "" => "index.html"
s3_file.upload_user_js: Creating...
bucket: "" => "s3page"
content_type: "" => "application/javascript"
debug: "" => "true"
file_path: "" => "./files/user.js"
name: "" => "user.js"
s3_file.upload_index_page: Creation complete after 0s
s3_file.upload_user_js: Creation complete after 0s Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
  • minio 界面
  • 设置浏览器访问
  • 直接访问

说明

terraform-provider-s3 功能还算不错,使用起来也比较简单,但是功能还不是很多,比如设置策略,配置通知。。。。,文件夹数据复制,
桶数据复制,但是实现起来还是相对简单的,可以参考provider 开发

参考资料

https://github.com/negronjl/terraform-provider-s3
https://github.com/rongfengliang/terraform-minio-s3-provider-demo

 
 
 
 

最新文章

  1. window搭建webpack,react,babel傻瓜教程
  2. HDU 4597 Play Game
  3. Javascript算术运算
  4. Adobe Flash CC 安装报错的解决办法
  5. android 下载图片出现SkImageDecoder::Factory returned null,BitmapFactory.Options压缩
  6. Hadoop Datanode节点无法启动(All directories in dfs.data.dir are invalid)
  7. drawBitmapMesh方法关键参数的说明
  8. Git单独checkout子目录
  9. android viewpager 深究
  10. JavaScript 父子页面相互调用总结
  11. 【转】Lombok 安装、入门 - 消除冗长的 java 代码
  12. mycat数据中间件、nginx
  13. Unity编辑器扩展-Custom List, displaying data your way
  14. A2D JS框架 - DES加密解密 与 Cookie的封装(C#与js互相加密解密)
  15. ES 6 系列 - 赋值的新方式:解构赋值
  16. 跨站请求伪造(CSRF)
  17. golang:send mail using smtp package
  18. 如何启用windows8, windows10中被停用的远程桌面,如何连接windows10远程桌面?
  19. idea操作快捷键
  20. 用户访问网页流程、DNS 解析流程

热门文章

  1. asp.net webform 不显示__doPostBack的原因及某种解决方法
  2. Android : alsa-lib 移植
  3. css经验之谈
  4. Tsi721信号及处理(转)
  5. $_SERVER[&#39;URI&#39;]
  6. 最新2018年三月可用Windows10激活密钥
  7. xshell 评估过期
  8. Access denied for user &#39;root&#39;@&#39;IP&#39; (using password:YES)解决方法
  9. POJ 1287 Networking(最小生成树裸题有重边)
  10. HDU 1846 Brave Game(巴什博弈超简单题)