{"id":714,"date":"2024-04-01T14:50:19","date_gmt":"2024-04-01T12:50:19","guid":{"rendered":"https:\/\/ilmarkerm.eu\/blog\/?p=714"},"modified":"2024-04-01T14:50:19","modified_gmt":"2024-04-01T12:50:19","slug":"building-oracle-cloud-infrastructure-with-terraform-storage","status":"publish","type":"post","link":"https:\/\/ilmarkerm.eu\/blog\/2024\/04\/building-oracle-cloud-infrastructure-with-terraform-storage\/","title":{"rendered":"Building Oracle Cloud infrastructure with Terraform &#8211; Storage"},"content":{"rendered":"\n<p>Continuing my series of exploring Oracle Cloud, with the help of Terraform code. <a href=\"https:\/\/ilmarkerm.eu\/blog\/2024\/03\/building-oracle-cloud-infrastructure-with-terraform-basics\/\" data-type=\"post\" data-id=\"704\">You can find the previous post here.<\/a> I will be referring to resources created in the earlier post.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Object store<\/h2>\n\n\n\n<p>Oracle Cloud does provide S3 style Object Storage, that is just called Buckets. Buckets can also speak S3 protocol, so they are usable for applications that speak S3.<\/p>\n\n\n\n<p>One difference from AWS S3 is that in Oracle Buckets the storage class\/tier is not at the object level, you have to specify during the creation of the Bucket if it is at the Standard or Archive tier.<\/p>\n\n\n\n<p>Here I create two Buckets, one in standard tier and one archival.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># object_storage.tf\n\ndata \"oci_objectstorage_namespace\" \"user_namespace\" {\n    compartment_id = oci_identity_compartment.compartment.id\n}\n\nresource \"oci_objectstorage_bucket\" \"standard_bucket\" {\n    # Referencing compartment from earlier\n    compartment_id = oci_identity_compartment.compartment.id\n    name = \"my-standard-tier-bucket\"\n    namespace = data.oci_objectstorage_namespace.user_namespace.namespace\n    access_type = \"NoPublicAccess\"\n    auto_tiering = \"Disabled\"\n    object_events_enabled = true\n    versioning = \"Enabled\"\n    storage_tier = \"Standard\"\n}\n\nresource \"oci_objectstorage_bucket\" \"archive_bucket\" {\n    # Referencing compartment from earlier\n    compartment_id = oci_identity_compartment.compartment.id\n    name = \"my-archival-bucket\"\n    namespace = data.oci_objectstorage_namespace.user_namespace.namespace\n    access_type = \"NoPublicAccess\"\n    auto_tiering = \"Disabled\"\n    object_events_enabled = false\n    versioning = \"Disabled\"\n    storage_tier = \"Archive\"\n}<\/code><\/pre>\n\n\n\n<p>And also adding some lifecycle policies. One to abort multipart uploads that have not finished in days and also one policy to delete old object versions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># object_storage.tf\n\n# Bucket lifecycle policies\n\nresource \"oci_objectstorage_object_lifecycle_policy\" \"standard_bucket\" {\n    bucket = oci_objectstorage_bucket.standard_bucket.name\n    namespace = data.oci_objectstorage_namespace.user_namespace.namespace\n\n    rules {\n        action = \"ABORT\"\n        is_enabled = true\n        name = \"delete-uncommitted-multipart-uploads\"\n        target = \"multipart-uploads\"\n        time_amount = 2\n        time_unit = \"DAYS\"\n    }\n    rules {\n        action = \"DELETE\"\n        is_enabled = true\n        name = \"delete-old-versions\"\n        target = \"previous-object-versions\"\n        time_amount = 60\n        time_unit = \"DAYS\"\n    }\n}\n\nresource \"oci_objectstorage_object_lifecycle_policy\" \"archive_bucket\" {\n    bucket = oci_objectstorage_bucket.archive_bucket.name\n    namespace = data.oci_objectstorage_namespace.user_namespace.namespace\n\n    rules {\n        action = \"ABORT\"\n        is_enabled = true\n        name = \"delete-uncommitted-multipart-uploads\"\n        target = \"multipart-uploads\"\n        time_amount = 2\n        time_unit = \"DAYS\"\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Block storage<\/h2>\n\n\n\n<p>A very good improvement over AWS is that in Oracle Cloud you can define declarative backup policies for block storage used in your compute instances. They are automatic snapshots, that are also cleaned up automatically after the retention period has expired. Lets start with that and define a backup policy that is executed every day at 0:00 UTC and kept for 60 days.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># block_storage.tf\n\nresource \"oci_core_volume_backup_policy\" \"test_policy\" {\n    compartment_id = oci_identity_compartment.compartment.id\n    display_name = \"Block storage backup policy for testing\"\n    schedules {\n        backup_type = \"INCREMENTAL\"\n        period = \"ONE_DAY\"\n        hour_of_day = 1\n        time_zone = \"UTC\"\n        # Keep backups for 60 days\n        retention_seconds = 3600*24*60\n    }\n}<\/code><\/pre>\n\n\n\n<p>There are also some backup policies already defined by Oracle. Sadly you cannot specify in data resource the name of the policy you want to address, so some array magic is needed when using it later.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># block_storage.tf\n\ndata \"oci_core_volume_backup_policies\" \"oracle_defined\" {}\n\n# For examining the output\noutput \"oracle_defined_volume_backup_policies\" {\n    value = data.oci_core_volume_backup_policies.oracle_defined\n}<\/code><\/pre>\n\n\n\n<p>Now lets create some block storage volumes. First volume is the cheapest, lowest performance; and the second volume is using balanced performance profile.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># block_storage.tf\n\nresource \"oci_core_volume\" \"test_volume\" {\n    compartment_id = oci_identity_compartment.compartment.id\n    # List availability domains\n    # oci iam availability-domain list\n    availability_domain = \"MpAX:EU-STOCKHOLM-1-AD-1\"\n    is_auto_tune_enabled = false\n    size_in_gbs = 50\n    # vpus_per_gb = 0 - low cost option\n    vpus_per_gb = 0\n}\n\nresource \"oci_core_volume\" \"silver_test_volume\" {\n    compartment_id = oci_identity_compartment.compartment.id\n    # List availability domains\n    # oci iam availability-domain list\n    availability_domain = \"MpAX:EU-STOCKHOLM-1-AD-1\"\n    is_auto_tune_enabled = false\n    size_in_gbs = 50\n    # vpus_per_gb = 10 - balanced performance option\n    vpus_per_gb = 10\n}<\/code><\/pre>\n\n\n\n<p>And lets attach the volumes to their backup policies. First volume the the policy I created earlier and the second volume to Oracle defined backup policy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>resource \"oci_core_volume_backup_policy_assignment\" \"test_volume\" {\n    asset_id = oci_core_volume.test_volume.id\n    # Attach to user defined policy\n    policy_id = oci_core_volume_backup_policy.test_policy.id\n}\n\nresource \"oci_core_volume_backup_policy_assignment\" \"silver_test_volume\" {\n    asset_id = oci_core_volume.silver_test_volume.id\n    # Attach to Silver policy\n    policy_id = data.oci_core_volume_backup_policies.oracle_defined.volume_backup_policies&#91;1].id\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Continuing my series of exploring Oracle Cloud, with the help of Terraform code. You can find the previous post here. I will be referring to resources created in the earlier post. Object store Oracle Cloud does provide S3 style Object Storage, that is just called Buckets. Buckets can also speak S3 protocol, so they are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[68,4],"class_list":["post-714","post","type-post","status-publish","format-standard","hentry","category-blog-entry","tag-oci","tag-oracle"],"_links":{"self":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/comments?post=714"}],"version-history":[{"count":3,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/714\/revisions"}],"predecessor-version":[{"id":717,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/714\/revisions\/717"}],"wp:attachment":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/media?parent=714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/categories?post=714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/tags?post=714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}