Skip to content

Commit 05e59f7

Browse files
authored
Merge pull request #95 from ovh/ava-s3-bucket-ovh-tf
Deploy Object Storage containers with OVHcloud TF provider
2 parents 264adde + b619375 commit 05e59f7

File tree

6 files changed

+60
-30
lines changed

6 files changed

+60
-30
lines changed

storage/s3-with-tf/README.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1-
# Create a simple Object container storage
1+
# Create a simple Object Storage container (S3™ compatible bucket)
22

3-
To run this TF code you need to set some environment variables (mandatory for AWS provider):
3+
The aim of this example is to deploy two Object Storage containers. One in 1-AZ region and one in 3-AZ region.
44

5+
### Set up
6+
- Install the [Terraform CLI](https://www.terraform.io/downloads.html)
7+
- Get the credentials from the OVHCloud Public Cloud project:
8+
- `application_key`
9+
- `application_secret`
10+
- `consumer_key`
11+
- Get the `service_name` (Public Cloud project ID)
12+
13+
### Demo
14+
- set the environment variables `OVH_APPLICATION_KEY`, `OVH_APPLICATION_SECRET`, `OVH_CONSUMER_KEY` and `OVH_CLOUD_PROJECT_SERVICE`
15+
16+
```bash
17+
# OVHcloud provider needed keys
18+
export OVH_ENDPOINT="ovh-eu"
19+
export OVH_APPLICATION_KEY="xxx"
20+
export OVH_APPLICATION_SECRET="xxx"
21+
export OVH_CONSUMER_KEY="xxx"
22+
export OVH_CLOUD_PROJECT_SERVICE="xxx"
523
```
6-
export AWS_ACCESS_KEY_ID="<your_access_key>"
7-
export AWS_SECRET_ACCESS_KEY="<your_secret_access_key>"
8-
```
24+
- Replace the value of your OVH_CLOUD_PROJECT_SERVICE environment variable in the [variables.tf](variables.tf) file (in the service_name variable)
25+
26+
`envsubst < variables.tf.template > variables.tf`
927

10-
To define the region (depending on our needs), follow this guide:
28+
To define the region of your containers (depending on our needs), follow this guide:
1129
https://help.ovhcloud.com/csm/en-gb-public-cloud-storage-s3-location?id=kb_article_view&sysparm_article=KB0047382
1230

13-
And then update the region variable in the `variables.tf` file.
31+
And then update the regions variables in the `variables.tf` file.
32+
33+
/!\ The region must be in uppercase!
1434

1535
Run the TF command `terraform apply`:
1636
```bash
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
# Create the bucket, the force_destroy argument will destroy the bucket even if it contains objects
2-
resource "aws_s3_bucket" "my-bucket-s3" {
3-
force_destroy = true
4-
bucket = "bucket-name" # the name must be unique within OVHcloud
1+
# Create a bucket, in 1-AZ region
2+
resource "ovh_cloud_project_storage" "my_s3_bucket_1az" {
3+
service_name = var.service_name
4+
region_name = var.region_1AZ
5+
name = "bucket-name" # the name must be unique within OVHcloud
6+
}
7+
8+
# Create a bucket, in 3-AZ region
9+
resource "ovh_cloud_project_storage" "my_s3_bucket_3az" {
10+
service_name = var.service_name
11+
region_name = var.region_3AZ
12+
name = "bucket-name-3az" # the name must be unique within OVHcloud
513
}

storage/s3-with-tf/output.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Output the Object Storage name after its creation
22

3-
output "my-bucket-s3" {
4-
value = "${aws_s3_bucket.my-bucket-s3.id}"
3+
output "my_s3_bucket_1az" {
4+
value = "${ovh_cloud_project_storage.my_s3_bucket_1az.name}"
5+
}
6+
7+
output "my_s3_bucket_3az" {
8+
value = "${ovh_cloud_project_storage.my_s3_bucket_3az.name}"
59
}

storage/s3-with-tf/provider.tf

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
terraform {
22
required_providers {
3-
aws = {
4-
source = "hashicorp/aws"
3+
ovh = {
4+
source = "ovh/ovh"
55
}
66
}
77
}
88

9-
# Configure the AWS Provider
10-
provider "aws" {
11-
region = "${var.region}"
12-
13-
# OVH implementation has no STS service
14-
skip_credentials_validation = true
15-
skip_requesting_account_id = true
16-
# the gra region is unknown to AWS hence skipping is needed.
17-
skip_region_validation = true
18-
endpoints {
19-
s3 = "https://s3.${var.region}.io.cloud.ovh.net"
20-
}
9+
provider "ovh" {
10+
endpoint = "ovh-eu"
2111
}

storage/s3-with-tf/variables.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "service_name" {
2+
default = "$OVH_CLOUD_PROJECT_SERVICE"
3+
}
4+
5+
variable "region_1AZ" {
6+
default = "GRA" #The region must be in uppercase
7+
}
8+
9+
variable "region_3AZ" {
10+
default = "EU-WEST-PAR" #The region must be in uppercase
11+
}

0 commit comments

Comments
 (0)