Skip to content

Commit

Permalink
add obs basic and website-hosting examples (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiChangkuo authored Nov 19, 2020
1 parent 083eb19 commit c962bda
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/obs/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Example: Basic OBS
This example provisions a OBS and put a file.
1 change: 1 addition & 0 deletions examples/obs/basic/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, I am an object.
32 changes: 32 additions & 0 deletions examples/obs/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
resource "huaweicloud_obs_bucket" "myexample" {
bucket = "myexample-bucket"
acl = "private"

tags = {
type = "bucket"
env = "Test"
}
}

# put myobject1 by content
resource "huaweicloud_obs_bucket_object" "myobject1" {
bucket = huaweicloud_obs_bucket.myexample.bucket
key = "myobject1"
content = "content of myobject1"
content_type = "application/xml"
}

# put myobject2 by source file
resource "huaweicloud_obs_bucket_object" "myobject2" {
bucket = huaweicloud_obs_bucket.myexample.bucket
key = "myobject2"
source = "hello.txt"
}

# put myobject3 by source file and encryption with default key
resource "huaweicloud_obs_bucket_object" "myobject3" {
bucket = huaweicloud_obs_bucket.myexample.bucket
key = "myobject3"
source = "hello.txt"
encryption = true
}
2 changes: 2 additions & 0 deletions examples/obs/website/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Example: OBS with Static Website Hosting
This example provisions a OBS with static website hosting.
10 changes: 10 additions & 0 deletions examples/obs/website/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>Hello OBS!</title>
<meta charset="utf-8">
</head>
<body>
<p>Welcome to use OBS static website hosting.</p>
<p> This is the 404 error page.</p>
</body>
</html>
10 changes: 10 additions & 0 deletions examples/obs/website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>Hello OBS!</title>
<meta charset="utf-8">
</head>
<body>
<p>Welcome to use OBS static website hosting.</p>
<p>This is the homepage.</p>
</body>
</html>
40 changes: 40 additions & 0 deletions examples/obs/website/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "huaweicloud_obs_bucket" "mywebsite" {
bucket = "mywebsite"

website {
index_document = "index.html"
error_document = "error.html"
}
}

# granting the Read-Only permission to anonymous users
resource "huaweicloud_obs_bucket_policy" "policy" {
bucket = huaweicloud_obs_bucket.mywebsite.bucket
policy = <<POLICY
{
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": {"ID": "*"},
"Action": ["GetObject"],
"Resource": "mywebsite/*"
}
]
}
POLICY
}

# put index.html
resource "huaweicloud_obs_bucket_object" "index" {
bucket = huaweicloud_obs_bucket.mywebsite.bucket
key = "index.html"
source = "index.html"
}

# put error.html
resource "huaweicloud_obs_bucket_object" "error" {
bucket = huaweicloud_obs_bucket.mywebsite.bucket
key = "error.html"
source = "error.html"
}

0 comments on commit c962bda

Please sign in to comment.