Skip to content

Commit 41b956e

Browse files
authored
Eginez/public buckets (#138)
* Changes to support public-buckets in terraform provider * Fixes documentation for public-buckets terraform * Fixing code review comments adding private bucket example * Amending/simplifying documentation
1 parent 2ba4c09 commit 41b956e

File tree

10 files changed

+96
-1
lines changed

10 files changed

+96
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ___ ____ _ ____ _ _____
2+
# / _ \| _ \ / \ / ___| | | ____|
3+
# | | | | |_) | / _ \| | | | | _|
4+
# | |_| | _ < / ___ | |___| |___| |___
5+
# \___/|_| \_/_/ \_\____|_____|_____|
6+
***
7+
## Creating buckets
8+
This example creates a single bucket inside a compartment
9+
10+
### Using this example
11+
* Update env-vars with the required information. Most examples use the same set of environment variables so you only need to do this once.
12+
* Source env-vars
13+
* `$ . env-vars`
14+
* Update `variables.tf` with your instance options.
15+
16+
### Files in the configuration
17+
18+
#### `env-vars`
19+
Is used to export the environmental variables used in the configuration. These are usually authentication related, be sure to exclude this file from your version control system. It's typical to keep this file outside of the configuration.
20+
21+
Before you plan, apply, or destroy the configuration source the file -
22+
`$ . env-vars`
23+
24+
#### `variables.tf`
25+
Defines the variables used in the configuration
26+
27+
#### `object.tf`
28+
Defines the buckets we are going to create
29+
30+
#### `provider.tf`
31+
Specifies and passes authentication details to the OBMCS TF provider
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "baremetal_objectstorage_bucket" "t" {
2+
compartment_id = "${var.compartment_ocid}"
3+
name = "BucketOne"
4+
access_type = "ObjectRead" // or NoPublicAccess
5+
namespace = "${var.namespace_name}"
6+
metadata = {
7+
"foo" = "bar"
8+
}
9+
}
10+
11+
resource "baremetal_objectstorage_bucket" "t_private" {
12+
compartment_id = "${var.compartment_ocid}"
13+
name = "PrivateBucket"
14+
//defaults to NoPublicAccess
15+
namespace = "${var.namespace_name}"
16+
metadata = {
17+
"foo" = "bar"
18+
}
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### Authentication details
2+
export TF_VAR_tenancy_ocid="<tenancy OCID"
3+
export TF_VAR_user_ocid="<user OCID>"
4+
export TF_VAR_fingerprint="<PEM key fingerprint>"
5+
export TF_VAR_private_key_path="<path to the private key that matches the fingerprint above>"
6+
7+
### Compartment
8+
export TF_VAR_compartment_ocid="<compartment OCID>"
9+
10+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider "baremetal" {
2+
tenancy_ocid = "${var.tenancy_ocid}"
3+
user_ocid = "${var.user_ocid}"
4+
fingerprint = "${var.fingerprint}"
5+
private_key_path = "${var.private_key_path}"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
variable "tenancy_ocid" {}
2+
variable "user_ocid" {}
3+
variable "fingerprint" {}
4+
variable "private_key_path" {}
5+
variable "namespace_name" {}
6+
variable "compartment_ocid" {}

docs/resources/objectstorage/bucket.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Provides an Objectstorage resource.
1010
resource "baremetal_objectstorage_bucket" "t" {
1111
compartment_id = "compartment_id"
1212
name = "name"
13+
access_type = "ObjectRead"
1314
namespace = "namespace"
1415
metadata = {
1516
"foo" = "bar"
@@ -25,6 +26,7 @@ The following arguments are supported:
2526
* `name` - (Required) The name of the bucket.
2627
* `namespace` - (Required) The namespace in which the bucket lives.
2728
* `metadata` - (Optional) Arbitrary string keys and values for user-defined metadata.
29+
* `access_type` - (Optional) Either "ObjectRead" or "NoPublicAccess". If not specified it defaults to "NoPublicAccess"
2830

2931
## Attributes Reference
3032

helpers_objectstorage.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
package main
44

5-
import "github.com/hashicorp/terraform/helper/schema"
5+
import (
6+
"github.com/hashicorp/terraform/helper/schema"
7+
"github.com/MustWin/baremetal-sdk-go"
8+
"github.com/hashicorp/terraform/helper/validation"
9+
)
610

711
func resourceObjectStorageMapToMetadata(rm map[string]interface{}) map[string]string {
812
result := map[string]string{}
@@ -28,6 +32,15 @@ var bucketSchema = map[string]*schema.Schema{
2832
Required: true,
2933
Computed: false,
3034
},
35+
"access_type": {
36+
Type: schema.TypeString,
37+
Computed: false,
38+
Default: baremetal.NoPublicAccess,
39+
Optional: true,
40+
ValidateFunc: validation.StringInSlice([]string{
41+
string(baremetal.NoPublicAccess),
42+
string(baremetal.ObjectRead)}, true),
43+
},
3144
"metadata": {
3245
Type: schema.TypeMap,
3346
Optional: true,

resource_obmcs_objectstorage_bucket.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func (s *BucketResourceCrud) SetData() {
7474
s.D.Set("metadata", s.Res.Metadata)
7575
s.D.Set("created_by", s.Res.CreatedBy)
7676
s.D.Set("time_created", s.Res.TimeCreated.String())
77+
s.D.Set("accessType", s.Res.AccessType)
7778
}
7879

7980
func (s *BucketResourceCrud) Create() (e error) {
@@ -86,6 +87,9 @@ func (s *BucketResourceCrud) Create() (e error) {
8687
metadata := resourceObjectStorageMapToMetadata(rawMetadata.(map[string]interface{}))
8788
opts.Metadata = metadata
8889
}
90+
91+
accessType, _ := s.D.GetOk("access_type") //guaranteed to be there with Default value
92+
opts.AccessType = baremetal.BucketAccessType(accessType.(string))
8993
s.Res, e = s.Client.CreateBucket(compartmentID, name, baremetal.Namespace(namespace), opts)
9094
return
9195
}
@@ -107,6 +111,8 @@ func (s *BucketResourceCrud) Update() (e error) {
107111
opts.Metadata = metadata
108112
}
109113

114+
accessType, _ := s.D.GetOk("access_type") //guaranteed to be there with Default value
115+
opts.AccessType = baremetal.BucketAccessType(accessType.(string))
110116
s.Res, e = s.Client.UpdateBucket(compartmentID, name, baremetal.Namespace(namespace), opts)
111117
return
112118
}

resource_obmcs_objectstorage_bucket_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type ResourceObjectstorageBucketTestSuite struct {
2424
ResourceName string
2525
Res *baremetal.Bucket
2626
Namespace baremetal.Namespace
27+
AccessType baremetal.BucketAccessType
2728
}
2829

2930
func (s *ResourceObjectstorageBucketTestSuite) SetupTest() {

resource_obmcs_objectstorage_object_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (s *ResourceObjectstorageObjectTestSuite) SetupTest() {
4444
resource "baremetal_objectstorage_bucket" "t" {
4545
compartment_id = "${var.compartment_id}"
4646
name = "bucketID"
47+
access_type="ObjectRead"
4748
namespace = "${var.namespace}"
4849
metadata = {
4950
"foo" = "bar"

0 commit comments

Comments
 (0)