Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
fix panic on empty err and usage of revision for detecting an update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoandredinis committed Mar 28, 2024
1 parent 117619b commit c916651
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 86 deletions.
2 changes: 1 addition & 1 deletion terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ ifeq ($(shell expr $(CURRENT_ULIMIT) \< 1024), 1)
@echo "ulimit -n is too low ($(CURRENT_ULIMIT)), please set ulimit -n 1024"
@exit -1
endif
TF_ACC=true go test ./test -v
TF_ACC=true go test ./test -v -run 'TestTerraform/TestLoginRule'

.PHONY: apply
apply: install
Expand Down
7 changes: 3 additions & 4 deletions terraform/gen/plural_resource.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,12 @@ func (r resourceTeleport{{.Name}}) Create(ctx context.Context, req tfsdk.CreateR
{{.VarName}}I, err = r.p.Client.{{.GetMethod}}(ctx, {{if .Namespaced}}defaults.Namespace, {{end}}id{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}})
if trace.IsNotFound(err) {
if bErr := backoff.Do(ctx); bErr != nil {
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(err), "{{.Kind}}"))
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(bErr), "{{.Kind}}"))
return
}
if tries >= r.p.RetryConfig.MaxTries {
diagMessage := fmt.Sprintf("Error reading {{.Name}} (tried %d times) - state outdated, please import resource", tries)
resp.Diagnostics.Append(diagFromWrappedErr(diagMessage, trace.Wrap(err), "{{.Kind}}"))
return
resp.Diagnostics.AddError(diagMessage, "{{.Kind}}")
}
continue
}
Expand Down Expand Up @@ -344,7 +343,7 @@ func (r resourceTeleport{{.Name}}) Update(ctx context.Context, req tfsdk.UpdateR
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", err, "{{.Kind}}"))
return
}
if {{.VarName}}Before.GetMetadata().ID != {{.VarName}}I.GetMetadata().ID || {{.HasStaticID}} {
if {{.VarName}}Before.GetMetadata().Revision != {{.VarName}}I.GetMetadata().Revision || {{.HasStaticID}} {
break
}

Expand Down
10 changes: 5 additions & 5 deletions terraform/gen/singular_resource.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ func (r resourceTeleport{{.Name}}) Create(ctx context.Context, req tfsdk.CreateR
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(err), "{{.Kind}}"))
return
}
if {{.VarName}}Before.GetMetadata().ID != {{.VarName}}I.GetMetadata().ID || {{.HasStaticID}} {
if {{.VarName}}Before.GetMetadata().Revision != {{.VarName}}I.GetMetadata().Revision || {{.HasStaticID}} {
break
}
if bErr := backoff.Do(ctx); bErr != nil {
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(err), "{{.Kind}}"))
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(bErr), "{{.Kind}}"))
return
}
if tries >= r.p.RetryConfig.MaxTries {
diagMessage := fmt.Sprintf("Error reading {{.Name}} (tried %d times) - state outdated, please import resource", tries)
resp.Diagnostics.Append(diagFromWrappedErr(diagMessage, trace.Wrap(err), "{{.Kind}}"))
resp.Diagnostics.AddError(diagMessage, "{{.Kind}}")
return
}
}
Expand Down Expand Up @@ -255,11 +255,11 @@ func (r resourceTeleport{{.Name}}) Update(ctx context.Context, req tfsdk.UpdateR
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(err), "{{.Kind}}"))
return
}
if {{.VarName}}Before.GetMetadata().ID != {{.VarName}}I.GetMetadata().ID || {{.HasStaticID}} {
if {{.VarName}}Before.GetMetadata().Revision != {{.VarName}}I.GetMetadata().Revision || {{.HasStaticID}} {
break
}
if bErr := backoff.Do(ctx); bErr != nil {
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(err), "{{.Kind}}"))
resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(bErr), "{{.Kind}}"))
return
}
if tries >= r.p.RetryConfig.MaxTries {
Expand Down
7 changes: 3 additions & 4 deletions terraform/provider/resource_teleport_access_list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions terraform/provider/resource_teleport_app.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions terraform/provider/resource_teleport_auth_preference.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions terraform/provider/resource_teleport_database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions terraform/provider/resource_teleport_device_trust.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions terraform/provider/resource_teleport_github_connector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions terraform/provider/resource_teleport_login_rule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions terraform/provider/resource_teleport_oidc_connector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions terraform/provider/resource_teleport_okta_import_rule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c916651

Please sign in to comment.