Skip to content

Commit 5d627d2

Browse files
iruAlex
andauthored
chore(lint): fix linting errors (#135)
* add azure to valid benchmark schemas * update docs * azure SP creds * refactor * gcp case * refactor * chore(fmt) * chore: add pre-commit * chore(lint): silent error handling https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/schema/resource_data.go#L206 * chore(lint): silent error handling https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/schema/resource_data.go#L206 * chore(lint): non required print * chore(lint): error handling * chore(lint): enforce linting * chore(lint): pre-commit options * chore(doc): readme/contrib update * chore(lint): fixes * chore(lint): revert. changed error for _ * chore(ci): test * chore(ci): test * chore(ci): test * chore(lint): revert. changed error for _ Co-authored-by: Alex <alex.qiu@sysdig.com>
1 parent 130b109 commit 5d627d2

File tree

58 files changed

+333
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+333
-281
lines changed

.envrc.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# prod/kubelab
2+
export SYSDIG_SECURE_API_TOKEN=
3+
export SYSDIG_MONITOR_API_TOKEN=

.github/workflows/ci-pull-request.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ jobs:
9494
uses: actions/checkout@v2
9595

9696
- name: Lint
97-
continue-on-error: true
98-
uses: golangci/golangci-lint-action@v1
97+
uses: golangci/golangci-lint-action@v2
9998
with:
100-
version: v1.27
99+
args: --timeout 30m

.pre-commit-config.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ repos:
22
- repo: local
33
hooks:
44
- id: fmt
5-
pass_filenames: false
65
name: fmt
6+
pass_filenames: false
77
entry: make fmt
88
language: system
99
- id: fmtcheck
@@ -12,7 +12,23 @@ repos:
1212
entry: make fmtcheck
1313
language: system
1414
- id: lint
15-
pass_filenames: false
1615
name: lint
16+
pass_filenames: false
1717
entry: make lint
1818
language: system
19+
# - id: test-compile
20+
# name: test-compile
21+
# pass_filenames: false
22+
# entry: make test-compile
23+
# language: system
24+
- id: test
25+
name: test
26+
pass_filenames: false
27+
entry: make test
28+
language: system
29+
- id: testacc
30+
name: testacc
31+
pass_filenames: false
32+
entry: make testacc
33+
language: system
34+

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<a href="https://terraform.io">
2+
<img src="https://raw.githubusercontent.com/hashicorp/terraform-provider-aws/main/.github/terraform_logo.svg" alt="Terraform logo" title="Terraform" align="right" height="50" />
3+
</a>
4+
5+
16
Terraform Provider for Sysdig
27
=============================
38

@@ -6,7 +11,6 @@ Terraform Provider for Sysdig
611
- Mailing list: [Google Groups](http://groups.google.com/group/terraform-tool)
712
- [Blog on how to use this provider with Sysdig Secure](https://sysdig.com/blog/using-terraform-for-container-security-as-code/)
813

9-
<img src="https://cdn.rawgit.com/hashicorp/terraform-website/master/content/source/assets/images/logo-hashicorp.svg" width="600px">
1014

1115
Requirements
1216
------------
@@ -29,7 +33,9 @@ Using the provider
2933
----------------------
3034
If you're building the provider, follow the instructions to [install it as a plugin.](https://www.terraform.io/docs/plugins/basics.html#installing-a-plugin) After placing it into your plugins directory, run `terraform init` to initialize it.
3135

32-
Developing the Provider
36+
---
37+
38+
Contribute
3339
---------------------------
3440

3541
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.13+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
@@ -54,3 +60,16 @@ If you want to execute the acceptance tests, you can run `make testacc`. Please
5460
```sh
5561
$ make testacc
5662
```
63+
64+
### Proposing PR's
65+
66+
* on pull-requests some validations are enforced.
67+
this can be prevented using [**pre-commit**](https://pre-commit.com)
68+
* Defined in [`/.pre-commit-config.yaml`](https://github.com/sysdiglabs/terraform-provider-sysdig/blob/master/.pre-commit-config.yaml)
69+
* for `testacc` some credentials are required, check [`/.envrc.template`](https://github.com/sysdiglabs/terraform-provider-sysdig/blob/master/.envrc.template)
70+
71+
72+
### Release
73+
74+
* Use **semver** for releases https://semver.org
75+
* To create a new release, create and push a new tag and it will be released by [`/.github/workflows/release.yml`](https://github.com/sysdiglabs/terraform-provider-sysdig/blob/master/.github/workflows/release.yml)

sysdig/data_source_sysdig_current_user.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ func dataSourceSysdigCurrentUserRead(ctx context.Context, d *schema.ResourceData
5353
}
5454

5555
d.SetId(strconv.Itoa(user.ID))
56-
d.Set("email", user.Email)
57-
d.Set("name", user.FirstName)
58-
d.Set("last_name", user.LastName)
59-
d.Set("system_role", user.SystemRole)
56+
_ = d.Set("email", user.Email)
57+
_ = d.Set("name", user.FirstName)
58+
_ = d.Set("last_name", user.LastName)
59+
_ = d.Set("system_role", user.SystemRole)
6060

6161
return nil
6262
}

sysdig/data_source_sysdig_fargate_workload_agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
910
"github.com/falcosecurity/kilt/runtimes/cloudformation/cfnpatcher"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -198,7 +199,7 @@ func dataSourceSysdigFargateWorkloadAgentRead(ctx context.Context, d *schema.Res
198199

199200
cdefChecksum := sha256.Sum256([]byte(containerDefinitions))
200201
d.SetId(fmt.Sprintf("%x", cdefChecksum))
201-
err = d.Set("output_container_definitions", *outputContainerDefinitions)
202+
_ = d.Set("output_container_definitions", *outputContainerDefinitions)
202203
if err != nil {
203204
return diag.FromErr(err)
204205
}

sysdig/data_source_sysdig_secure_notification_channel.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,22 @@ func dataSourceSysdigNotificationChannelRead(ctx context.Context, d *schema.Reso
117117
}
118118

119119
d.SetId(strconv.Itoa(nc.ID))
120-
d.Set("version", nc.Version)
121-
d.Set("name", nc.Name)
122-
d.Set("enabled", nc.Enabled)
123-
d.Set("type", nc.Type)
124-
d.Set("recipients", strings.Join(nc.Options.EmailRecipients, ","))
125-
d.Set("topics", strings.Join(nc.Options.SnsTopicARNs, ","))
126-
d.Set("api_key", nc.Options.APIKey)
127-
d.Set("url", nc.Options.Url)
128-
d.Set("channel", nc.Options.Channel)
129-
d.Set("account", nc.Options.Account)
130-
d.Set("service_key", nc.Options.ServiceKey)
131-
d.Set("service_name", nc.Options.ServiceName)
132-
d.Set("routing_key", nc.Options.RoutingKey)
133-
d.Set("notify_when_ok", nc.Options.NotifyOnOk)
134-
d.Set("notify_when_resolved", nc.Options.NotifyOnResolve)
135-
d.Set("send_test_notification", nc.Options.SendTestNotification)
120+
_ = d.Set("version", nc.Version)
121+
_ = d.Set("name", nc.Name)
122+
_ = d.Set("enabled", nc.Enabled)
123+
_ = d.Set("type", nc.Type)
124+
_ = d.Set("recipients", strings.Join(nc.Options.EmailRecipients, ","))
125+
_ = d.Set("topics", strings.Join(nc.Options.SnsTopicARNs, ","))
126+
_ = d.Set("api_key", nc.Options.APIKey)
127+
_ = d.Set("url", nc.Options.Url)
128+
_ = d.Set("channel", nc.Options.Channel)
129+
_ = d.Set("account", nc.Options.Account)
130+
_ = d.Set("service_key", nc.Options.ServiceKey)
131+
_ = d.Set("service_name", nc.Options.ServiceName)
132+
_ = d.Set("routing_key", nc.Options.RoutingKey)
133+
_ = d.Set("notify_when_ok", nc.Options.NotifyOnOk)
134+
_ = d.Set("notify_when_resolved", nc.Options.NotifyOnResolve)
135+
_ = d.Set("send_test_notification", nc.Options.SendTestNotification)
136136

137137
// When we receive a notification channel of type OpsGenie,
138138
// the API sends us the URL, but we are configuring the API
@@ -147,8 +147,9 @@ func dataSourceSysdigNotificationChannelRead(ctx context.Context, d *schema.Reso
147147
return diag.FromErr(err)
148148
}
149149
key := regex.FindStringSubmatch(nc.Options.Url)[1]
150-
d.Set("api_key", key)
151-
d.Set("url", "")
150+
_ = d.Set("api_key", key)
151+
_ = d.Set("url", "")
152+
152153
}
153154
return nil
154155
}

sysdig/data_source_sysdig_secure_trusted_cloud_identity.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,26 @@ func dataSourceSysdigSecureTrustedCloudIdentityRead(ctx context.Context, d *sche
6464
}
6565

6666
d.SetId(identity)
67-
d.Set("identity", identity)
67+
_ = d.Set("identity", identity)
6868

6969
provider := d.Get("cloud_provider")
7070
switch provider {
7171
case "aws", "gcp":
7272
// If identity is an ARN, attempt to extract certain fields
7373
parsedArn, err := arn.Parse(identity)
7474
if err == nil {
75-
d.Set("aws_account_id", parsedArn.AccountID)
76-
75+
_ = d.Set("aws_account_id", parsedArn.AccountID)
7776
if parsedArn.Service == "iam" && strings.HasPrefix(parsedArn.Resource, "role/") {
78-
d.Set("aws_role_name", strings.TrimPrefix(parsedArn.Resource, "role/"))
77+
_ = d.Set("aws_role_name", strings.TrimPrefix(parsedArn.Resource, "role/"))
7978
}
8079
}
8180
case "azure":
8281
// If identity is an Azure tenantID/clientID, separate into each part
8382
tenantID, clientID, err := parseAzureCreds(identity)
8483
if err == nil {
85-
d.Set("azure_tenant_id", tenantID)
86-
d.Set("azure_client_id", clientID)
84+
_ = d.Set("azure_tenant_id", tenantID)
85+
_ = d.Set("azure_client_id", clientID)
86+
8787
}
8888
}
8989
return nil

sysdig/data_source_sysdig_user.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ func dataSourceSysdigUserRead(ctx context.Context, d *schema.ResourceData, meta
5757
}
5858

5959
d.SetId(strconv.Itoa(u.ID))
60-
d.Set("version", u.Version)
61-
d.Set("system_role", u.SystemRole)
62-
d.Set("first_name", u.FirstName)
63-
d.Set("last_name", u.LastName)
60+
_ = d.Set("version", u.Version)
61+
_ = d.Set("system_role", u.SystemRole)
62+
_ = d.Set("first_name", u.FirstName)
63+
_ = d.Set("last_name", u.LastName)
6464

6565
return nil
6666

sysdig/internal/client/common/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (u *User) ToJSON() io.Reader {
2323

2424
func UserFromJSON(body []byte) User {
2525
var result userWrapper
26-
json.Unmarshal(body, &result)
26+
_ = json.Unmarshal(body, &result)
2727

2828
return result.User
2929
}

0 commit comments

Comments
 (0)