Skip to content
This repository was archived by the owner on Mar 16, 2022. It is now read-only.

Commit 6cda83d

Browse files
authored
Merge pull request #4 from Ouest-France/ghaction
* Migrate from Travis to Github Actions * Lint code to pass checks
2 parents 4e34ff7 + 38830b5 commit 6cda83d

14 files changed

+206
-109
lines changed

.github/workflows/pr.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: PR
2+
on: [pull_request]
3+
jobs:
4+
build:
5+
name: Build
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Set up Go 1.13
9+
uses: actions/setup-go@v1
10+
with:
11+
go-version: 1.13
12+
id: go
13+
14+
- name: Check out code into the Go module directory
15+
uses: actions/checkout@v1
16+
17+
- name: Build
18+
run: go build -o terraform-provider-phpipam_${GITHUB_REF}
19+
20+
- name: Setup Lint
21+
run: curl -LO https://github.com/golangci/golangci-lint/releases/download/v1.19.1/golangci-lint-1.19.1-linux-amd64.tar.gz && tar -xf golangci-lint-1.19.1-linux-amd64.tar.gz
22+
23+
- name: Lint
24+
run: golangci-lint-1.19.1-linux-amd64/golangci-lint run

.github/workflows/tag.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Tag
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Set up Go 1.13
13+
uses: actions/setup-go@v1
14+
with:
15+
go-version: 1.13
16+
id: go
17+
18+
- name: Get the version
19+
id: get_version
20+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
21+
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v1
24+
25+
- name: Build
26+
run: go build -o terraform-provider-phpipam_${{ steps.get_version.outputs.VERSION }}
27+
28+
- name: Setup Lint
29+
run: curl -LO https://github.com/golangci/golangci-lint/releases/download/v1.19.1/golangci-lint-1.19.1-linux-amd64.tar.gz && tar -xf golangci-lint-1.19.1-linux-amd64.tar.gz
30+
31+
- name: Lint
32+
run: golangci-lint-1.19.1-linux-amd64/golangci-lint run
33+
34+
- name: Upload binaries to release
35+
uses: svenstaro/upload-release-action@v1-release
36+
with:
37+
repo_token: ${{ secrets.GITHUB_TOKEN }}
38+
file: terraform-provider-phpipam_${{ steps.get_version.outputs.VERSION }}
39+
asset_name: terraform-provider-phpipam_${{ steps.get_version.outputs.VERSION }}
40+
tag: ${{ github.ref }}
41+
overwrite: true

.travis.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

plugin/providers/phpipam/address_structure.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"errors"
55
"strconv"
66

7-
"github.com/hashicorp/terraform/helper/schema"
87
"github.com/Ouest-France/phpipam-sdk-go/controllers/addresses"
98
"github.com/Ouest-France/phpipam-sdk-go/phpipam"
9+
"github.com/hashicorp/terraform/helper/schema"
1010
)
1111

1212
// resourceAddressOptionalFields represents all the fields that are optional in
@@ -196,25 +196,37 @@ func expandAddress(d *schema.ResourceData) addresses.Address {
196196

197197
// flattenAddress sets fields in a *schema.ResourceData with fields supplied by
198198
// the input addresses.Address. This is used in read operations.
199-
func flattenAddress(a addresses.Address, d *schema.ResourceData) {
199+
func flattenAddress(a addresses.Address, d *schema.ResourceData) error {
200200
d.SetId(strconv.Itoa(a.ID))
201-
d.Set("address_id", a.ID)
202-
d.Set("subnet_id", a.SubnetID)
203-
d.Set("ip_address", a.IPAddress)
204-
d.Set("is_gateway", a.IsGateway)
205-
d.Set("description", a.Description)
206-
d.Set("hostname", a.Hostname)
207-
d.Set("mac_address", a.MACAddress)
208-
d.Set("owner", a.Owner)
209-
d.Set("state_tag_id", a.Tag)
210-
d.Set("skip_ptr_record", a.PTRIgnore)
211-
d.Set("ptr_record_id", a.PTRRecordID)
212-
d.Set("device_id", a.DeviceID)
213-
d.Set("switch_port_label", a.Port)
214-
d.Set("note", a.Note)
215-
d.Set("last_seen", a.LastSeen)
216-
d.Set("exclude_ping", a.ExcludePing)
217-
d.Set("edit_date", a.EditDate)
201+
202+
fields := map[string]interface{}{
203+
"address_id": a.ID,
204+
"subnet_id": a.SubnetID,
205+
"ip_address": a.IPAddress,
206+
"is_gateway": a.IsGateway,
207+
"description": a.Description,
208+
"hostname": a.Hostname,
209+
"mac_address": a.MACAddress,
210+
"owner": a.Owner,
211+
"state_tag_id": a.Tag,
212+
"skip_ptr_record": a.PTRIgnore,
213+
"ptr_record_id": a.PTRRecordID,
214+
"device_id": a.DeviceID,
215+
"switch_port_label": a.Port,
216+
"note": a.Note,
217+
"last_seen": a.LastSeen,
218+
"exclude_ping": a.ExcludePing,
219+
"edit_date": a.EditDate,
220+
}
221+
222+
for field, value := range fields {
223+
err := d.Set(field, value)
224+
if err != nil {
225+
return err
226+
}
227+
}
228+
229+
return nil
218230
}
219231

220232
// addressSearchInSubnet provides the address search functionality for both the

plugin/providers/phpipam/custom_field_structure.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"reflect"
66
"regexp"
77

8-
"github.com/hashicorp/terraform/helper/schema"
98
"github.com/Ouest-France/phpipam-sdk-go/controllers/addresses"
109
"github.com/Ouest-France/phpipam-sdk-go/controllers/subnets"
1110
"github.com/Ouest-France/phpipam-sdk-go/controllers/vlans"
11+
"github.com/hashicorp/terraform/helper/schema"
1212
)
1313

1414
// customFieldFilterSchema returns a *schema.Schema for the custom_field_filter
@@ -43,7 +43,7 @@ func customFieldFilterSchema(conflicts []string) *schema.Schema {
4343
// this function will be updated.
4444
func customFieldFilter(data, search map[string]interface{}) (bool, error) {
4545
// zero-length or nil map is a panic. This should never happen
46-
if search == nil || len(search) == 0 {
46+
if len(search) == 0 {
4747
panic("Zero length or nil map passed as search terms to customFieldFilter")
4848
}
4949

plugin/providers/phpipam/data_source_phpipam_address.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package phpipam
33
import (
44
"errors"
55

6-
"github.com/hashicorp/terraform/helper/schema"
76
"github.com/Ouest-France/phpipam-sdk-go/controllers/addresses"
7+
"github.com/hashicorp/terraform/helper/schema"
88
)
99

1010
func dataSourcePHPIPAMAddress() *schema.Resource {
@@ -42,7 +42,10 @@ func dataSourcePHPIPAMAddressRead(d *schema.ResourceData, meta interface{}) erro
4242
if len(out) != 1 {
4343
return errors.New("Your search returned zero or multiple results. Please correct your search and try again")
4444
}
45-
flattenAddress(out[0], d)
45+
err = flattenAddress(out[0], d)
46+
if err != nil {
47+
return err
48+
}
4649
fields, err := c.GetAddressCustomFields(out[0].ID)
4750
if err != nil {
4851
return err

plugin/providers/phpipam/data_source_phpipam_first_free_address.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func dataSourcePHPIPAMFirstFreeAddressRead(d *schema.ResourceData, meta interfac
3333
}
3434

3535
d.SetId(out)
36-
d.Set("ip_address", out)
36+
err = d.Set("ip_address", out)
3737

38-
return nil
38+
return err
3939
}

plugin/providers/phpipam/data_source_phpipam_section.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package phpipam
33
import (
44
"errors"
55

6-
"github.com/hashicorp/terraform/helper/schema"
76
"github.com/Ouest-France/phpipam-sdk-go/controllers/sections"
7+
"github.com/hashicorp/terraform/helper/schema"
88
)
99

1010
func dataSourcePHPIPAMSection() *schema.Resource {
@@ -34,6 +34,7 @@ func dataSourcePHPIPAMSectionRead(d *schema.ResourceData, meta interface{}) erro
3434
default:
3535
return errors.New("section_id or name not defined, cannot proceed with reading data")
3636
}
37-
flattenSection(out, d)
38-
return nil
37+
err = flattenSection(out, d)
38+
39+
return err
3940
}

plugin/providers/phpipam/data_source_phpipam_subnet.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"errors"
55
"fmt"
66

7-
"github.com/hashicorp/terraform/helper/schema"
87
"github.com/Ouest-France/phpipam-sdk-go/controllers/subnets"
8+
"github.com/hashicorp/terraform/helper/schema"
99
)
1010

1111
func dataSourcePHPIPAMSubnet() *schema.Resource {
@@ -43,7 +43,10 @@ func dataSourcePHPIPAMSubnetRead(d *schema.ResourceData, meta interface{}) error
4343
if len(out) != 1 {
4444
return errors.New("Your search returned zero or multiple results. Please correct your search and try again")
4545
}
46-
flattenSubnet(out[0], d)
46+
err = flattenSubnet(out[0], d)
47+
if err != nil {
48+
return err
49+
}
4750
fields, err := c.GetSubnetCustomFields(out[0].ID)
4851
if err != nil {
4952
return err

plugin/providers/phpipam/data_source_phpipam_vlan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package phpipam
33
import (
44
"errors"
55

6-
"github.com/hashicorp/terraform/helper/schema"
76
"github.com/Ouest-France/phpipam-sdk-go/controllers/vlans"
7+
"github.com/hashicorp/terraform/helper/schema"
88
)
99

1010
func dataSourcePHPIPAMVLAN() *schema.Resource {
@@ -39,6 +39,6 @@ func dataSourcePHPIPAMVLANRead(d *schema.ResourceData, meta interface{}) error {
3939
default:
4040
return errors.New("vlan_id or number not defined, cannot proceed with reading data")
4141
}
42-
flattenVLAN(out, d)
43-
return nil
42+
err := flattenVLAN(out, d)
43+
return err
4444
}

0 commit comments

Comments
 (0)