-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add obs basic and website-hosting examples (#674)
- Loading branch information
1 parent
083eb19
commit c962bda
Showing
7 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello, I am an object. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |