Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #64 from 5-stones/feat/storage-zone
Browse files Browse the repository at this point in the history
This merge adds support for managing storage zones.
  • Loading branch information
fho authored Jun 19, 2022
2 parents 2aba0e8 + bc126db commit ddb042c
Show file tree
Hide file tree
Showing 20 changed files with 1,102 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BUG FIXES:
IMPROVEMENTS:

* provider: upgrade github.com/hashicorp/terraform-plugin-docs to version 0.10.1
* resource/storagezone: add the ability to manage storagezone resources

## 0.7.1 (Juni 08, 2022)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This repository provides a [Terraform](https://terraform.io) provider for the
[Bunny.net CDN platform](https://bunny.net/). \
It currently only supports to manage Pull Zones.
It supports to manage Pull and Storage Zones.

## Development

Expand Down
40 changes: 40 additions & 0 deletions docs/resources/storagezone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bunny_storagezone Resource - bunny"
subcategory: ""
description: |-
---

# bunny_storagezone (Resource)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the storage zone.

### Optional

- `custom_404_file_path` (String) The path to the custom file that will be returned in a case of 404.
- `origin_url` (String) The origin URL of the storage zone.
- `region` (String) The code of the main storage zone region (Possible values: DE, NY, LA, SG).
- `replication_regions` (Set of String) The list of replication zones for the storage zone (Possible values: DE, NY, LA, SG, SYD). Replication zones cannot be removed once the zone has been created.
- `rewrite_404_to_200` (Boolean) Rewrite 404 status code to 200 for URLs without extension.

### Read-Only

- `deleted` (Boolean)
- `files_stored` (Number) The number of files stored in the storage zone.
- `id` (String) The ID of this resource.
- `password` (String, Sensitive) The password granting read/write access to the storage zone.
- `read_only_password` (String, Sensitive) The password granting read-only access to the storage zone.
- `storage_used` (Number) The amount of storage used in the storage zone in bytes.
- `user_id` (String)


4 changes: 4 additions & 0 deletions examples/resources/storagezone_resource/basic.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "bunny_storagezone" "mysz" {
name = "testsz"
region = "DE"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/AlekSi/pointer v1.2.0
github.com/google/go-cmp v0.5.8
github.com/google/uuid v1.3.0
github.com/hashicorp/terraform-plugin-docs v0.10.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0
Expand All @@ -21,7 +22,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ func New() *schema.Provider {
},
},
ResourcesMap: map[string]*schema.Resource{
"bunny_pullzone": resourcePullZone(),
"bunny_edgerule": resourceEdgeRule(),
"bunny_hostname": resourceHostname(),
"bunny_pullzone": resourcePullZone(),
"bunny_edgerule": resourceEdgeRule(),
"bunny_hostname": resourceHostname(),
"bunny_storagezone": resourceStorageZone(),
},
ConfigureContextFunc: newProvider,
}
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/resource_edgerule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func defPullZoneHostname(pullzoneName string) string {
}

func TestAccEdgeRule_full(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()

tfPz := fmt.Sprintf(`
resource "bunny_pullzone" "mypz" {
Expand Down Expand Up @@ -311,7 +311,7 @@ resource "bunny_edgerule" "er3" {
}

func TestAccEdgeRule_basic(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()
tf := fmt.Sprintf(`
resource "bunny_pullzone" "mypz" {
name = "%s"
Expand Down Expand Up @@ -363,7 +363,7 @@ resource "bunny_edgerule" "myer" {
}

func TestAccEdgeRule_delete(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()

tfPz := fmt.Sprintf(`
resource "bunny_pullzone" "mypz" {
Expand Down Expand Up @@ -421,7 +421,7 @@ resource "bunny_pullzone" "mypz" {
}

func TestAccEdgeRule_enable_disable(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()

tfPz := fmt.Sprintf(`
resource "bunny_pullzone" "mypz" {
Expand Down Expand Up @@ -558,8 +558,8 @@ resource "bunny_edgerule" "er2" {
}

func TestAccEdgeRule_changePullZoneID(t *testing.T) {
pzName1 := randPullZoneName()
pzName2 := randPullZoneName()
pzName1 := randResourceName()
pzName2 := randResourceName()

tfPz := fmt.Sprintf(`
resource "bunny_pullzone" "pz1" {
Expand Down
16 changes: 8 additions & 8 deletions internal/provider/resource_hostname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func sortHostnames(hostnames []*bunny.Hostname) {
}

func TestAccHostname_basic(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()
tf := fmt.Sprintf(`
resource "bunny_pullzone" "pz" {
name = "%s"
Expand Down Expand Up @@ -121,7 +121,7 @@ resource "bunny_hostname" "h1" {
}

func TestAccHostname_addRemove(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()
hostname1 := randHostname()
hostname2 := randHostname()
hostname3 := randHostname()
Expand Down Expand Up @@ -244,7 +244,7 @@ resource "bunny_hostname" "h2" {
}

func TestAccHostname_DefiningDuplicateHostnamesFails(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()
tf := fmt.Sprintf(`
resource "bunny_pullzone" "pz" {
name = "%s"
Expand Down Expand Up @@ -275,7 +275,7 @@ resource "bunny_hostname" "h2" {
}

func TestAccHostname_DefiningDefPullZoneHostnameFails(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()
tf := fmt.Sprintf(`
resource "bunny_pullzone" "pz" {
name = "%s"
Expand All @@ -300,7 +300,7 @@ resource "bunny_hostname" "h1" {
}

func TestAccCertificateOneof(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()
tf := fmt.Sprintf(`
resource "bunny_pullzone" "pz" {
name = "%s"
Expand Down Expand Up @@ -333,7 +333,7 @@ resource "bunny_hostname" "h1" {
}

func TestAccCertificateCanBeSetWhenLoadFreeCertIsDisabled(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()
tf := fmt.Sprintf(`
resource "bunny_pullzone" "pz" {
name = "%s"
Expand Down Expand Up @@ -366,7 +366,7 @@ resource "bunny_hostname" "h1" {
}

func TestAccCertificates(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()
hostname := randHostname()

resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -486,7 +486,7 @@ resource "bunny_hostname" "h1" {
func TestAccHostname_StateIsValidWhenCertUploadFails(t *testing.T) {
t.Skip("disabled, because test sends 800kiB of bogus data to bunny api, which is not kind")

pzName := randPullZoneName()
pzName := randResourceName()
hostname := randHostname()

// The bunny API does not return an error if the posted data is not a
Expand Down
12 changes: 4 additions & 8 deletions internal/provider/resource_pullzone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
bunny "github.com/simplesurance/bunny-go"
)

func randPullZoneName() string {
return resource.PrefixedUniqueId(resourcePrefix)
}

func randHostname() string {
return resource.PrefixedUniqueId(resourcePrefix) + ".test"
}
Expand Down Expand Up @@ -173,7 +169,7 @@ func TestAccPullZone_basic(t *testing.T) {
*/
attrs := pullZoneWanted{
TerraformResourceName: "bunny_pullzone.mytest1",
Name: randPullZoneName(),
Name: randResourceName(),
OriginURL: "https://tabletennismap.de",
EnableGeoZoneAsia: true,
EnableGeoZoneEU: true,
Expand Down Expand Up @@ -285,7 +281,7 @@ func TestAccPullZone_full(t *testing.T) {
VerifyOriginSSL: ptr.ToBool(true),
ZoneSecurityEnabled: ptr.ToBool(true),
ZoneSecurityIncludeHashRemoteIP: ptr.ToBool(false),
Name: ptr.ToString(randPullZoneName()),
Name: ptr.ToString(randResourceName()),
// TODO: Test StorageZoneID
ZoneSecurityKey: ptr.ToString("xyz"),

Expand Down Expand Up @@ -523,7 +519,7 @@ resource "bunny_pullzone" "%s" {
}

func TestAccPullZone_CaseInsensitiveOrderIndependentFields(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()

resource.Test(t, resource.TestCase{
Providers: testProviders,
Expand Down Expand Up @@ -772,7 +768,7 @@ func pzDiff(t *testing.T, a, b interface{}) []string {
}

func TestAccPullZone_OriginURLAndStorageZoneIDAreExclusive(t *testing.T) {
pzName := randPullZoneName()
pzName := randResourceName()

resource.Test(t, resource.TestCase{
Providers: testProviders,
Expand Down
Loading

0 comments on commit ddb042c

Please sign in to comment.