https://gitlab.com/LondonAppDev/recipe-app-api-devops
Google Cloud Storage
Object storage solution in GCP
Unstructured Data storage
>> Image
>> Video
>> Binary File, etc…
Cloud storage can be used for long term archival storage
Can be access object over http, Rest API
Let’s see in action
Với option location type, thì chúng ta có những tuỳ chọn khác
Giờ click create thôi
Google Cloud Storage with Terraform
Create GCS and upload file via terraform
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket
Bạn tạo 1 thư mục GCS
trong GCS tạo file provider.tf
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.85.0"
}
}
}
provider "google" {
# Configuration options
project = "terraform-gcp-326702"
region = "us-central1"
zone = "us-central1-a"
credentials = "keys.json"
}
Giờ tạo file main.tf
resource "google_storage_bucket" "GCS1" {
name = "tf-course-bucket-from-terraform"
storage_class = "NEARLINE"
location = "US-CENTRAL1"
labels = {
"env" = "tf_env"
"dep" = "complience"
}
uniform_bucket_level_access = true
lifecycle_rule {
condition {
age = 5
}
action {
type = "SetStorageClass"
storage_class = "COLDLINE"
}
}
retention_policy {
is_locked = true
retention_period = 864000
}
}
resource "google_storage_bucket_object" "picture" {
name = "vodafone_logo"
bucket = google_storage_bucket.GCS1.name
source = "vodafone.jpg"
}
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket_object
link trên sẽ giải thích cho bạn
Sau khi chạy terraform apply
Nếu bây giờ anh em delete bucket lỗi
vì trong code chúng ta có retention_policy
– (Optional) Configuration of the bucket’s data retention policy for how long objects in the bucket should be retained. Structure is documented below.
The retention_policy
block supports:
is_locked
– (Optional) If set totrue
, the bucket will be locked and permanently restrict edits to the bucket’s retention policy. Caution: Locking a bucket is an irreversible action.retention_period
– (Required) The period of time, in seconds, that objects in the bucket must be retained and cannot be deleted, overwritten, or archived. The value must be less than 2,147,483,647 seconds.
Giờ chúng ta cần làm gì?