Skip to content

Commit

Permalink
fix workflows not pulling private repo (#2)
Browse files Browse the repository at this point in the history
* Add Tests
* Fix Linter Errors
* Run sequentially so dont need to update plan
  • Loading branch information
jmtx1020 authored May 6, 2024
1 parent 29bc41e commit 00cdb40
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ jobs:
with:
go-version-file: "go.mod"
cache: true
- run: go mod download
- run: |-
git config --global url.https://[email protected]/.insteadOf https://github.com/
go mod download
env:
GOPRIVATE: "github.com/jmtx1020/go_quicknode"
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
- run: go build -v .
- name: Run linters
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0
Expand Down Expand Up @@ -62,6 +67,7 @@ jobs:
timeout-minutes: 15
strategy:
fail-fast: false
max-parallel: 1
matrix:
# list whatever Terraform versions here you would like to support
terraform:
Expand All @@ -83,13 +89,16 @@ jobs:
QUICKNODE_API_TOKEN: ${{ secrets.QUICKNODE_API_TOKEN }}
QUICKNODE_API_HOST: ${{ secrets.QUICKNODE_API_HOST }}
GOPRIVATE: "github.com/jmtx1020/go_quicknode"
- name: Setup access for private go modules
run: |
git config --global url."ssh://[email protected]/".insteadOf https://github.com/
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
- run: |-
git config --global url.https://[email protected]/.insteadOf https://github.com/
go mod download
env:
GOPRIVATE: "github.com/jmtx1020/go_quicknode"
- env:
TF_ACC: "1"
QUICKNODE_API_TOKEN: ${{ secrets.QUICKNODE_API_TOKEN }}
QUICKNODE_API_HOST: ${{ secrets.QUICKNODE_API_HOST }}
run: |-
go test -v -cover ./internal/provider/
timeout-minutes: 10
7 changes: 7 additions & 0 deletions internal/provider/destination_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ func (r *destinationResource) Update(ctx context.Context, req resource.UpdateReq
plan.Service.ValueString(),
int(plan.PayloadType.ValueInt64()),
)
if err != nil {
resp.Diagnostics.AddError(
"Update - Error Creating QuickNode Destination.",
"Update - Could not creating QuickNode Name "+state.Name.ValueString()+": "+err.Error(),
)
return
}

plan.ID = types.StringValue(dest.ID)
plan.Token = types.StringValue(dest.Token)
Expand Down
34 changes: 30 additions & 4 deletions internal/provider/notification_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,32 @@ func (n *notificationResource) Create(ctx context.Context, req resource.CreateRe
}

// toggle the notification (enabled or disabled) based on plan values
if plan.Enabled.ValueBool() == true {
if plan.Enabled.ValueBool() {
tflog.Debug(ctx, "Enabling Notification")
err = notificationsAPI.ToggleNotificationByID(
notification.ID,
true,
)
if err != nil {
resp.Diagnostics.AddError(
"Error enabling notification",
"Could not enable notification, unexpected error: "+err.Error(),
)
return
}
} else {
tflog.Debug(ctx, "Disabling Notification")
err = notificationsAPI.ToggleNotificationByID(
notification.ID,
false,
)
if err != nil {
resp.Diagnostics.AddError(
"Error disabling notification",
"Could not disable notification, unexpected error: "+err.Error(),
)
return
}
}

plan.ID = types.StringValue(notification.ID)
Expand Down Expand Up @@ -183,8 +197,6 @@ func (n *notificationResource) Read(ctx context.Context, req resource.ReadReques
notif_bytes := []byte(notif.Expression)
notif_expr_b64 := base64.StdEncoding.EncodeToString(notif_bytes)

tflog.Debug(ctx, "READ METHOD")

state.ID = types.StringValue(notif.ID)
state.Name = types.StringValue(notif.Name)
state.Enabled = types.BoolValue(notif.Enabled)
Expand Down Expand Up @@ -236,18 +248,32 @@ func (n *notificationResource) Update(ctx context.Context, req resource.UpdateRe
}

// toggle the notification (enabled or disabled) based on plan values
if plan.Enabled.ValueBool() == true {
if plan.Enabled.ValueBool() {
tflog.Debug(ctx, "Enabling Notification")
err = notificationsAPI.ToggleNotificationByID(
notif.ID,
true,
)
if err != nil {
resp.Diagnostics.AddError(
"Error enabling notification",
"Could not enable notification, unexpected error: "+err.Error(),
)
return
}
} else {
tflog.Debug(ctx, "Disabling Notification")
err = notificationsAPI.ToggleNotificationByID(
notif.ID,
false,
)
if err != nil {
resp.Diagnostics.AddError(
"Error disabling notification",
"Could not disable notification, unexpected error: "+err.Error(),
)
return
}
}

notif_bytes := []byte(notif.Expression)
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (p *quicknodeProvider) Configure(ctx context.Context, req provider.Configur
return
}

// if the practicioner provided a configuration value for an of the attributes
// if the practitioner provided a configuration value for an of the attributes
// it must be a known value
if config.Host.IsUnknown() {
resp.Diagnostics.AddAttributeError(
Expand Down

0 comments on commit 00cdb40

Please sign in to comment.