Skip to content

Commit

Permalink
Merge pull request #2 from germanbrew/refactoring/code-adjustments
Browse files Browse the repository at this point in the history
Refactoring and code adjustments
  • Loading branch information
kimdre authored May 25, 2024
2 parents f5310c0 + 342ee3c commit 957b8c4
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 33 deletions.
8 changes: 4 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a third-party provier, which is not maintained by Hashicorp. You have
to download and install it on your own. Pick the binary for the target operating
system from the [releases list](https://github.com/timohirt/terraform-provider-hetznerdns/releases)
system from the [releases list](https://github.com/germanbrew/terraform-provider-hetznerdns/releases)
and download the archive.

## Installing the Provider
Expand All @@ -14,9 +14,9 @@ nicly with the Terraform Registry. This means that you have to create or migrate
to a slighly different directory structure where you put the provide binaries.

```bash
$ mkdir -p ~/.terraform.d/plugins/github.com/timohirt/hetznerdns/1.0.5/linux_amd64
$ mkdir -p ~/.terraform.d/plugins/github.com/germanbrew/hetznerdns/1.0.5/linux_amd64
$ tar xzf terraform-provider-hetznerdns_1.0.5_linux_amd64.tar.gz
$ mv ./terraform-provider-hetznerdns ~/.terraform.d/plugins/github.com/timohirt/hetznerdns/1.0.5/linux_amd64/terraform-provider-hetznerdns_v1.0.5
$ mv ./terraform-provider-hetznerdns ~/.terraform.d/plugins/github.com/germanbrew/hetznerdns/1.0.5/linux_amd64/terraform-provider-hetznerdns_v1.0.5
```

As you can see above, the version as well as the operating system is now included in
Expand All @@ -31,7 +31,7 @@ Add the following to your `terraform.tf`.
terraform {
required_providers {
hetznerdns = {
source = "github.com/timohirt/hetznerdns"
source = "github.com/germanbrew/hetznerdns"
}
}
required_version = ">= 1.0"
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Terraform Provider for Hetzner DNS

![CI Build](https://github.com/timohirt/terraform-provider-hetznerdns/workflows/CI%20Build/badge.svg?branch=master)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/timohirt/terraform-provider-hetznerdns)
![GitHub](https://img.shields.io/github/license/timohirt/terraform-provider-hetznerdns)

Read about what I learnt while [implementing this Terraform Provider](http://www.timohirt.de/blog/implementing-a-terraform-provider/).
![CI Build](https://github.com/germanbrew/terraform-provider-hetznerdns/workflows/CI%20Build/badge.svg?branch=master)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/germanbrew/terraform-provider-hetznerdns)
![GitHub](https://img.shields.io/github/license/germanbrew/terraform-provider-hetznerdns)

**This provider is on published on the Terraform registry**.

This project has been forked from
[germanbrew/terraform-provider-hetznerdns](https://github.com/germanbrew/terraform-provider-hetznerdns)
which is unfortunately no longer maintained.

You can find resources and data sources
[documentation](https://registry.terraform.io/providers/timohirt/hetznerdns/latest/docs)
[documentation](https://registry.terraform.io/providers/germanbrew/hetznerdns/latest/docs)
there or [here](docs).

## Requirements
Expand All @@ -20,7 +22,7 @@ there or [here](docs).
## Installing and Using this Plugin

You most likely want to download the provider from [Terraform
Registry](https://registry.terraform.io/providers/timohirt/hetznerdns/latest/docs).
Registry](https://registry.terraform.io/providers/germanbrew/hetznerdns/latest/docs).
If you want or need to install the provider locally, take a look at
[INSTALL](./INSTALL.md).

Expand All @@ -33,7 +35,7 @@ add the following to your `terraform.tf`:
terraform {
required_providers {
hetznerdns = {
source = "timohirt/hetznerdns"
source = "germanbrew/hetznerdns"
version = "2.1.0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ git tag v1.0.17
$ git push --tags
```

Then navigate your browser to the GitHub [releases page of this repository](https://github.com/timohirt/terraform-provider-hetznerdns/releases).
Then navigate your browser to the GitHub [releases page of this repository](https://github.com/germanbrew/terraform-provider-hetznerdns/releases).

Download `terraform-provider-hetznerdns_1.0.17_SHA256SUMS` from the
list of assets associated with this release. The version might by
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/timohirt/terraform-provider-hetznerdns
module github.com/germanbrew/terraform-provider-hetznerdns

go 1.16

Expand Down
7 changes: 3 additions & 4 deletions hetznerdns/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"io"
"io/ioutil"
"log"
"net/http"
"strings"
Expand Down Expand Up @@ -96,11 +95,11 @@ func (c *Client) doHTTPRequest(apiToken string, method string, url string, body
}

func parseUnprocessableEntityError(resp *http.Response) (*UnprocessableEntityError, error) {
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
defer resp.Body.Close()

if err != nil {
return nil, fmt.Errorf("Error reading HTTP response body: %e", err)
return nil, fmt.Errorf("error reading HTTP response body: %e", err)
}
var unprocessableEntityError UnprocessableEntityError
err = parseJSON(body, &unprocessableEntityError)
Expand Down Expand Up @@ -160,7 +159,7 @@ func (c *Client) doPutRequest(url string, bodyJSON interface{}) (*http.Response,
}

func readAndParseJSONBody(resp *http.Response, respType interface{}) error {
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
defer resp.Body.Close()

if err != nil {
Expand Down
11 changes: 5 additions & 6 deletions hetznerdns/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"testing"

Expand All @@ -22,7 +21,7 @@ func TestClientCreateZoneSuccess(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, Zone{ID: "12345", Name: "mydomain.com", TTL: 3600}, *zone)
assert.NotNil(t, requestBodyReader, "The request body should not be nil")
jsonRequestBody, _ := ioutil.ReadAll(requestBodyReader)
jsonRequestBody, _ := io.ReadAll(requestBodyReader)
assert.Equal(t, `{"name":"mydomain.com","ttl":3600}`, string(jsonRequestBody))
}

Expand Down Expand Up @@ -61,7 +60,7 @@ func TestClientUpdateZoneSuccess(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, zoneWithUpdates, *updatedZone)
assert.NotNil(t, requestBodyReader, "The request body should not be nil")
jsonRequestBody, _ := ioutil.ReadAll(requestBodyReader)
jsonRequestBody, _ := io.ReadAll(requestBodyReader)
assert.Equal(t, zoneWithUpdatesJSON, string(jsonRequestBody))
}

Expand Down Expand Up @@ -162,7 +161,7 @@ func TestClientCreateRecordSuccess(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, Record{ZoneID: "wwwlsksjjenm", ID: "12345678", Name: "zone1.online", TTL: &aTTL, Type: "A", Value: "192.168.1.1"}, *record)
assert.NotNil(t, requestBodyReader, "The request body should not be nil")
jsonRequestBody, _ := ioutil.ReadAll(requestBodyReader)
jsonRequestBody, _ := io.ReadAll(requestBodyReader)
assert.Equal(t, `{"zone_id":"wwwlsksjjenm","type":"A","name":"zone1.online","value":"192.168.1.1","ttl":3600}`, string(jsonRequestBody))
}

Expand All @@ -189,7 +188,7 @@ func TestClientUpdateRecordSuccess(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, recordWithUpdates, *updatedRecord)
assert.NotNil(t, requestBodyReader, "The request body should not be nil")
jsonRequestBody, _ := ioutil.ReadAll(requestBodyReader)
jsonRequestBody, _ := io.ReadAll(requestBodyReader)
assert.Equal(t, recordWithUpdatesJSON, string(jsonRequestBody))
}

Expand Down Expand Up @@ -231,7 +230,7 @@ func (f TestClient) RoundTrip(req *http.Request) (*http.Response, error) {

var jsonBody io.ReadCloser = nil
if f.config.responseBodyJSON != nil {
jsonBody = ioutil.NopCloser(bytes.NewReader(f.config.responseBodyJSON))
jsonBody = io.NopCloser(bytes.NewReader(f.config.responseBodyJSON))
}
resp := http.Response{StatusCode: f.config.responseHTTPStatus, Body: jsonBody}
return &resp, nil
Expand Down
2 changes: 1 addition & 1 deletion hetznerdns/data_source_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hetznerdns
import (
"fmt"

"github.com/timohirt/terraform-provider-hetznerdns/hetznerdns/api"
"github.com/germanbrew/terraform-provider-hetznerdns/hetznerdns/api"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
5 changes: 3 additions & 2 deletions hetznerdns/primary_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package hetznerdns

import (
"context"
"log"

"github.com/germanbrew/terraform-provider-hetznerdns/hetznerdns/api"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/timohirt/terraform-provider-hetznerdns/hetznerdns/api"
"log"
)

func resourcePrimaryServer() *schema.Resource {
Expand Down
3 changes: 2 additions & 1 deletion hetznerdns/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package hetznerdns

import (
"context"

"github.com/germanbrew/terraform-provider-hetznerdns/hetznerdns/api"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/timohirt/terraform-provider-hetznerdns/hetznerdns/api"
)

// Provider creates and return a Terraform resource provider
Expand Down
5 changes: 3 additions & 2 deletions hetznerdns/resource_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package hetznerdns

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"log"

"github.com/timohirt/terraform-provider-hetznerdns/hetznerdns/api"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/germanbrew/terraform-provider-hetznerdns/hetznerdns/api"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
5 changes: 3 additions & 2 deletions hetznerdns/resource_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package hetznerdns

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"log"

"github.com/timohirt/terraform-provider-hetznerdns/hetznerdns/api"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/germanbrew/terraform-provider-hetznerdns/hetznerdns/api"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"github.com/germanbrew/terraform-provider-hetznerdns/hetznerdns"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
plugin "github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/timohirt/terraform-provider-hetznerdns/hetznerdns"
)

func main() {
Expand Down

0 comments on commit 957b8c4

Please sign in to comment.