Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ay/fix/acceptance-tes…
Browse files Browse the repository at this point in the history
…ts/improve-checks
  • Loading branch information
1riatsila1 committed Nov 14, 2024
2 parents 1ac7e62 + 78eeeaf commit d6da107
Show file tree
Hide file tree
Showing 73 changed files with 1,347 additions and 1,324 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,10 @@ jobs:
with:
go-version-file: 'go.mod'
cache: true
- name: Import GPG key
uses: crazy-max/[email protected]
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/[email protected]
with:
args: release --clean
env:
# GitHub sets the GITHUB_TOKEN secret automatically.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
11 changes: 2 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,9 @@ checksum:
algorithm: sha256
signs:
- artifacts: checksum
cmd: just
args:
# if you are using this in a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--local-user"
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
- "sign"
release:
extra_files:
- glob: 'terraform-registry-manifest.json'
Expand Down
7 changes: 7 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ setup-dev:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.1
go install github.com/segmentio/golines@latest

build-local:
go install github.com/goreleaser/goreleaser/v2@latest
goreleaser release --clean --skip=publish,validate

sign:
signhpe --in dist/$(ls dist | grep SHA256SUMS) --keyring --project "HPE Aruba Networking UXI Terraform Provider" --out ./dist

test-client +ARGS='':
cd {{ CONFIG_API_CLIENT_DIR }} && go test -v ./... -race -covermode=atomic -coverprofile=.coverage {{ ARGS }}

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package config

const (
MaxRetriesFor429 = 10
MaxRetriesForTooManyRequests = 10
)
2 changes: 1 addition & 1 deletion internal/provider/datasources/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (d *agentDataSource) Read(
AgentsGet(ctx).
Id(state.Filter.AgentID.ValueString())

agentResponse, response, err := util.RetryFor429(request.Execute)
agentResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_agent")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/datasources/agent_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (d *agentGroupAssignmentDataSource) Read(
request := d.client.ConfigurationAPI.
AgentGroupAssignmentsGet(ctx).
Id(state.Filter.AgentGroupAssignmentID)
agentGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute)
agentGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_agent_group_assignment")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/datasources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (d *groupDataSource) Read(
GroupsGet(ctx).
Id(*state.Filter.GroupID)

groupResponse, response, err := util.RetryFor429(request.Execute)
groupResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_group")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/datasources/network_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (d *networkGroupAssignmentDataSource) Read(
request := d.client.ConfigurationAPI.
NetworkGroupAssignmentsGet(ctx).
Id(state.Filter.NetworkGroupAssignmentID)
networkGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute)
networkGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_network_group_assignment")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/datasources/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (d *sensorDataSource) Read(
SensorsGet(ctx).
Id(state.Filter.SensorID.ValueString())

sensorResponse, response, err := util.RetryFor429(request.Execute)
sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_sensor")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/datasources/sensor_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (d *sensorGroupAssignmentDataSource) Read(
request := d.client.ConfigurationAPI.
SensorGroupAssignmentsGet(ctx).
Id(state.Filter.SensorGroupAssignmentID)
sensorGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute)
sensorGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("create", "uxi_sensor_group_assignment")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/datasources/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (d *serviceTestDataSource) Read(
ServiceTestsGet(ctx).
Id(state.Filter.ServiceTestID.ValueString())

serviceTestResponse, response, err := util.RetryFor429(request.Execute)
serviceTestResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_service_test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func (d *serviceTestGroupAssignmentDataSource) Read(
request := d.client.ConfigurationAPI.
ServiceTestGroupAssignmentsGet(ctx).
Id(state.Filter.ServiceTestGroupAssignmentID)
serviceTestGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute)
serviceTestGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(
request.Execute,
)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_service_test_group_assignment")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/datasources/wired_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (d *wiredNetworkDataSource) Read(
request := d.client.ConfigurationAPI.
WiredNetworksGet(ctx).
Id(state.Filter.WiredNetworkID)
networkResponse, response, err := util.RetryFor429(request.Execute)
networkResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_wired_network")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/datasources/wireless_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (d *wirelessNetworkDataSource) Read(
request := d.client.ConfigurationAPI.
WirelessNetworksGet(ctx).
Id(state.Filter.WirelessNetworkID)
networkResponse, response, err := util.RetryFor429(request.Execute)
networkResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_wireless_network")
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/resources/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (r *agentResource) Read(
request := r.client.ConfigurationAPI.
AgentsGet(ctx).
Id(state.ID.ValueString())
agentResponse, response, err := util.RetryFor429(request.Execute)
agentResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_agent")
Expand Down Expand Up @@ -178,7 +178,7 @@ func (r *agentResource) Update(
request := r.client.ConfigurationAPI.
AgentsPatch(ctx, plan.ID.ValueString()).
AgentsPatchRequest(*patchRequest)
agent, response, err := util.RetryFor429(request.Execute)
agent, response, err := util.RetryForTooManyRequests(request.Execute)

errorPresent, errorDetail := util.RaiseForStatus(response, err)

Expand Down Expand Up @@ -220,7 +220,7 @@ func (r *agentResource) Delete(

request := r.client.ConfigurationAPI.AgentsDelete(ctx, state.ID.ValueString())

_, response, err := util.RetryFor429(request.Execute)
_, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/resources/agent_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (r *agentGroupAssignmentResource) Create(
request := r.client.ConfigurationAPI.
AgentGroupAssignmentsPost(ctx).
AgentGroupAssignmentsPostRequest(*postRequest)
agentGroupAssignment, response, err := util.RetryFor429(request.Execute)
agentGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down Expand Up @@ -149,7 +149,7 @@ func (r *agentGroupAssignmentResource) Read(
request := r.client.ConfigurationAPI.
AgentGroupAssignmentsGet(ctx).
Id(state.ID.ValueString())
agentGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute)
agentGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_agent_group_assignment")
Expand Down Expand Up @@ -204,7 +204,7 @@ func (r *agentGroupAssignmentResource) Delete(

request := r.client.ConfigurationAPI.
AgentGroupAssignmentDelete(ctx, state.ID.ValueString())
_, response, err := util.RetryFor429(request.Execute)
_, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/resources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *groupResource) Create(
request := r.client.ConfigurationAPI.
GroupsPost(ctx).
GroupsPostRequest(*groups_post_request)
group, response, err := util.RetryFor429(request.Execute)
group, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down Expand Up @@ -207,7 +207,7 @@ func (r *groupResource) Update(
request := r.client.ConfigurationAPI.
GroupsPatch(ctx, plan.ID.ValueString()).
GroupsPatchRequest(*patchRequest)
group, response, err := util.RetryFor429(request.Execute)
group, response, err := util.RetryForTooManyRequests(request.Execute)

errorPresent, errorDetail := util.RaiseForStatus(response, err)

Expand Down Expand Up @@ -249,7 +249,7 @@ func (r *groupResource) Delete(
// Delete existing group using the plan_id
request := r.client.ConfigurationAPI.GroupsDelete(ctx, state.ID.ValueString())

_, response, err := util.RetryFor429(request.Execute)
_, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand All @@ -271,7 +271,7 @@ func (r *groupResource) getGroup(
id string,
) (*config_api_client.GroupsGetItem, *string) {
request := r.client.ConfigurationAPI.GroupsGet(ctx).Id(id)
groupResponse, response, err := util.RetryFor429(request.Execute)
groupResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/resources/network_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *networkGroupAssignmentResource) Create(
request := r.client.ConfigurationAPI.
NetworkGroupAssignmentsPost(ctx).
NetworkGroupAssignmentsPostRequest(*postRequest)
networkGroupAssignment, response, err := util.RetryFor429(request.Execute)
networkGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down Expand Up @@ -154,7 +154,7 @@ func (r *networkGroupAssignmentResource) Read(
request := r.client.ConfigurationAPI.
NetworkGroupAssignmentsGet(ctx).
Id(state.ID.ValueString())
networkGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute)
networkGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_network_group_assignment")
Expand Down Expand Up @@ -216,7 +216,7 @@ func (r *networkGroupAssignmentResource) Delete(

request := r.client.ConfigurationAPI.
NetworkGroupAssignmentsDelete(ctx, state.ID.ValueString())
_, response, err := util.RetryFor429(request.Execute)
_, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/resources/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (r *sensorResource) Read(
request := r.client.ConfigurationAPI.
SensorsGet(ctx).
Id(state.ID.ValueString())
sensorResponse, response, err := util.RetryFor429(request.Execute)
sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_sensor")
Expand Down Expand Up @@ -178,7 +178,7 @@ func (r *sensorResource) Update(
request := r.client.ConfigurationAPI.
SensorsPatch(ctx, plan.ID.ValueString()).
SensorsPatchRequest(*patchRequest)
sensor, response, err := util.RetryFor429(request.Execute)
sensor, response, err := util.RetryForTooManyRequests(request.Execute)

errorPresent, errorDetail := util.RaiseForStatus(response, err)

Expand Down
6 changes: 3 additions & 3 deletions internal/provider/resources/sensor_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *sensorGroupAssignmentResource) Create(
request := r.client.ConfigurationAPI.
SensorGroupAssignmentsPost(ctx).
SensorGroupAssignmentsPostRequest(*postRequest)
sensorGroupAssignment, response, err := util.RetryFor429(request.Execute)
sensorGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down Expand Up @@ -154,7 +154,7 @@ func (r *sensorGroupAssignmentResource) Read(
request := r.client.ConfigurationAPI.
SensorGroupAssignmentsGet(ctx).
Id(state.ID.ValueString())
sensorGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute)
sensorGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("create", "uxi_sensor_group_assignment")
Expand Down Expand Up @@ -215,7 +215,7 @@ func (r *sensorGroupAssignmentResource) Delete(
// Delete existing sensorGroupAssignment using the plan_id
request := r.client.ConfigurationAPI.
SensorGroupAssignmentsDelete(ctx, state.ID.ValueString())
_, response, err := util.RetryFor429(request.Execute)
_, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resources/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *serviceTestResource) Read(
request := r.client.ConfigurationAPI.
ServiceTestsGet(ctx).
Id(state.ID.ValueString())
sensorResponse, response, err := util.RetryFor429(request.Execute)
sensorResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_service_test")
Expand Down
8 changes: 5 additions & 3 deletions internal/provider/resources/service_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *serviceTestGroupAssignmentResource) Create(
request := r.client.ConfigurationAPI.
ServiceTestGroupAssignmentsPost(ctx).
ServiceTestGroupAssignmentsPostRequest(*postRequest)
serviceTestGroupAssignment, response, err := util.RetryFor429(request.Execute)
serviceTestGroupAssignment, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down Expand Up @@ -154,7 +154,9 @@ func (r *serviceTestGroupAssignmentResource) Read(
request := r.client.ConfigurationAPI.
ServiceTestGroupAssignmentsGet(ctx).
Id(state.ID.ValueString())
serviceTestGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute)
serviceTestGroupAssignmentResponse, response, err := util.RetryForTooManyRequests(
request.Execute,
)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_service_test_group_assignment")
Expand Down Expand Up @@ -217,7 +219,7 @@ func (r *serviceTestGroupAssignmentResource) Delete(
request := r.client.ConfigurationAPI.
ServiceTestGroupAssignmentsDelete(ctx, state.ID.ValueString())

_, response, err := util.RetryFor429(request.Execute)
_, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resources/wired_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *wiredNetworkResource) Read(
request := r.client.ConfigurationAPI.
WiredNetworksGet(ctx).
Id(state.ID.ValueString())
networkResponse, response, err := util.RetryFor429(request.Execute)
networkResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_wired_network")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resources/wireless_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *wirelessNetworkResource) Read(
request := r.client.ConfigurationAPI.
WirelessNetworksGet(ctx).
Id(state.ID.ValueString())
networkResponse, response, err := util.RetryFor429(request.Execute)
networkResponse, response, err := util.RetryForTooManyRequests(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

errorSummary := util.GenerateErrorSummary("read", "uxi_wireless_network")
Expand Down
8 changes: 5 additions & 3 deletions internal/provider/util/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import (
"github.com/aruba-uxi/terraform-provider-hpeuxi/internal/provider/config"
)

func RetryFor429[T any](f func() (T, *http.Response, error)) (T, *http.Response, error) {
func RetryForTooManyRequests[T any](
f func() (T, *http.Response, error),
) (T, *http.Response, error) {
var result T
var err error
var httpResponse *http.Response

for i := 0; i < config.MaxRetriesFor429; i++ {
for i := 0; i < config.MaxRetriesForTooManyRequests; i++ {
result, httpResponse, err = f()

if httpResponse == nil || httpResponse.StatusCode != 429 {
if httpResponse == nil || httpResponse.StatusCode != http.StatusTooManyRequests {
return result, httpResponse, err
}

Expand Down
Loading

0 comments on commit d6da107

Please sign in to comment.