

My Automated Lab project: #6 Create a S3 Bucket with Terraform
source link: https://www.virtualtothecore.com/my-automated-lab-project-6-create-a-s3-bucket-with-terraform/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

My Automated Lab project: #6 Create a S3 Bucket with Terraform
To complete my setup, once I deployed all my virtual machines in the previous articles, I also need a S3 bucket to be later used in Veeam as an object storage. And obviously, I can also automated this part.
For this project, I will use AWS S3. In AWS I need a user that can create and manage the buckets. Keep in mind to select Programmatic access in Access type to get Access Key ID and Secret Key:

then, we grab its access key, and we use them in our Terraform project. In the Terraform project folder, I create the file variables.tf:
variable "aws_access_key" { default = "XXXXXXXXXXXXXX" } variable "aws_secret_key" { default = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } variable "region" { default = "eu-south-1" } variable "bucket_name" { default = "veeam-iac-demo" }
and I edit the default values with my own data. Then, I define the project in the usual file main.tf:
# 1. we load the AWS provider, and define the variables for region and access credentials provider "aws" { access_key = "${var.aws_access_key}" secret_key = "${var.aws_secret_key}" region = "${var.region}" } # 2. we create the new S3 bucket resource "aws_s3_bucket" "veeam-iac-demo" { bucket = "${var.bucket_name}" object_lock_enabled = true } # 3. we define the ownership of the bucket resource "aws_s3_bucket_ownership_controls" "veeam-iac-demo" { bucket = aws_s3_bucket.veeam-iac-demo.id rule { object_ownership = "BucketOwnerPreferred" } } # 4. we set the ACL for the bucket to be private resource "aws_s3_bucket_acl" "veeam-iac-demo" { depends_on = [aws_s3_bucket_ownership_controls.veeam-iac-demo] bucket = aws_s3_bucket.veeam-iac-demo.id acl = "private" } # 5. we configure Object Lock for the bucket resource "aws_s3_bucket_object_lock_configuration" "veeam-iac-demo" { bucket = aws_s3_bucket.veeam-iac-demo.id rule { default_retention { mode = "COMPLIANCE" days = 5 } } }
The file has five steps, described directly in the comments.
Then, as always, I initialize Terraform, that will read the information about the needed provider and prepare Terraform.

and, if all is fine, I execute it with terraform apply

If I go into my AWS console I can see my new bucket up and ready!

Scrolling down in the properties, I can check that Object Lock is enabled with the parameters I’ve defined.

Recommend
-
17
Automated ConfigMgr Setup in Azure DevTest Lab
-
16
Use an existing S3 bucket or DynamoDB table for your Amplify project by Rene Brandel | on 24 NOV 2020 | in Announce...
-
9
iBucket 5.0Create your bucket list, achieve goals & plan trips togetherProdu...
-
6
Kuba Martin for Spacelift...
-
8
Create an S3 Bucket on AWS using Terraform In this article, I will show you how to use Terraform to create an S3 bucket on AWS. Before proceeding, I assume that you are familiar with S3 bucket if not then you can click
-
14
How to Manage Terraform State in an AWS S3 Bucket In this article, we will see what a Terraform state is and how to manage it on an S3 Bucket. We will also see what "lock" is in Terraform and how to implement it. To implement this,...
-
5
Percona Terraform Provider DISCLAIMER This is an experimental project, use on your own risk. This project is not covered by Percona Support Requirements
-
7
My Automated Lab project: #1 Install and configure the needed tools Luca Dell'Oca,
-
8
The configuration files This time, I have a little bit different configuration: As always, you can grab the files in my Github repo at
-
9
My Automated Lab project: #4 Deploy the VMs from templates using Terraform Luca Dell'Oca,
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK