diff --git a/terraform/gen/main.go b/terraform/gen/main.go index 291c9aac1..2533d8c49 100644 --- a/terraform/gen/main.go +++ b/terraform/gen/main.go @@ -62,8 +62,6 @@ type payload struct { UpsertMethodArity int // WithSecrets value for a withSecrets param of Get method (empty means no param used) WithSecrets string - // GetWithoutContext indicates that get method has no context parameter (workaround for the User) - GetWithoutContext bool // ID id value on create and import ID string // RandomMetadataName indicates that Metadata.Name must be generated (supported by plural resources only) @@ -218,8 +216,9 @@ var ( TypeName: "GithubConnectorV3", VarName: "githubConnector", GetMethod: "GetGithubConnector", - CreateMethod: "UpsertGithubConnector", + CreateMethod: "CreateGithubConnector", UpdateMethod: "UpsertGithubConnector", + UpsertMethodArity: 2, DeleteMethod: "DeleteGithubConnector", WithSecrets: "true", ID: "githubConnector.Metadata.Name", @@ -234,8 +233,9 @@ var ( TypeName: "OIDCConnectorV3", VarName: "oidcConnector", GetMethod: "GetOIDCConnector", - CreateMethod: "UpsertOIDCConnector", + CreateMethod: "CreateOIDCConnector", UpdateMethod: "UpsertOIDCConnector", + UpsertMethodArity: 2, DeleteMethod: "DeleteOIDCConnector", WithSecrets: "true", ID: "oidcConnector.Metadata.Name", @@ -250,8 +250,9 @@ var ( TypeName: "SAMLConnectorV2", VarName: "samlConnector", GetMethod: "GetSAMLConnector", - CreateMethod: "UpsertSAMLConnector", + CreateMethod: "CreateSAMLConnector", UpdateMethod: "UpsertSAMLConnector", + UpsertMethodArity: 2, DeleteMethod: "DeleteSAMLConnector", WithSecrets: "true", ID: "samlConnector.Metadata.Name", @@ -283,8 +284,9 @@ var ( TypeName: "RoleV6", VarName: "role", GetMethod: "GetRole", - CreateMethod: "UpsertRole", + CreateMethod: "CreateRole", UpdateMethod: "UpsertRole", + UpsertMethodArity: 2, DeleteMethod: "DeleteRole", ID: "role.Metadata.Name", Kind: "role", @@ -330,10 +332,10 @@ var ( VarName: "user", GetMethod: "GetUser", CreateMethod: "CreateUser", - UpdateMethod: "UpdateUser", + UpdateMethod: "UpsertUser", + UpsertMethodArity: 2, DeleteMethod: "DeleteUser", WithSecrets: "false", - GetWithoutContext: true, ID: "user.Metadata.Name", Kind: "user", HasStaticID: false, diff --git a/terraform/gen/plural_data_source.go.tpl b/terraform/gen/plural_data_source.go.tpl index 8ce988456..88d8cdf03 100644 --- a/terraform/gen/plural_data_source.go.tpl +++ b/terraform/gen/plural_data_source.go.tpl @@ -69,7 +69,7 @@ func (r dataSourceTeleport{{.Name}}) Read(ctx context.Context, req tfsdk.ReadDat return } - {{.VarName}}I, err := r.p.Client.{{.GetMethod}}({{if not .GetWithoutContext}}ctx, {{end}}id.Value{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) + {{.VarName}}I, err := r.p.Client.{{.GetMethod}}(ctx, id.Value{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(err), "{{.Kind}}")) return diff --git a/terraform/gen/plural_resource.go.tpl b/terraform/gen/plural_resource.go.tpl index 6ae017591..dbf406e37 100644 --- a/terraform/gen/plural_resource.go.tpl +++ b/terraform/gen/plural_resource.go.tpl @@ -119,7 +119,7 @@ func (r resourceTeleport{{.Name}}) Create(ctx context.Context, req tfsdk.CreateR {{end}} id := {{.VarName}}Resource.Metadata.Name - _, err = r.p.Client.{{.GetMethod}}({{if not .GetWithoutContext}}ctx, {{end}}id{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) + _, err = r.p.Client.{{.GetMethod}}(ctx, id{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) if !trace.IsNotFound(err) { if err == nil { existErr := fmt.Sprintf("{{.Name}} exists in Teleport. Either remove it (tctl rm {{.Kind}}/%v)"+ @@ -160,7 +160,7 @@ func (r resourceTeleport{{.Name}}) Create(ctx context.Context, req tfsdk.CreateR backoff := backoff.NewDecorr(r.p.RetryConfig.Base, r.p.RetryConfig.Cap, clockwork.NewRealClock()) for { tries = tries + 1 - {{.VarName}}I, err = r.p.Client.{{.GetMethod}}({{if not .GetWithoutContext}}ctx, {{end}}id{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) + {{.VarName}}I, err = r.p.Client.{{.GetMethod}}(ctx, 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}}")) @@ -232,7 +232,7 @@ func (r resourceTeleport{{.Name}}) Read(ctx context.Context, req tfsdk.ReadResou return } - {{.VarName}}I, err := r.p.Client.{{.GetMethod}}({{if not .GetWithoutContext}}ctx, {{end}}id.Value{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) + {{.VarName}}I, err := r.p.Client.{{.GetMethod}}(ctx, id.Value{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) if trace.IsNotFound(err) { resp.State.RemoveResource(ctx) return @@ -301,7 +301,7 @@ func (r resourceTeleport{{.Name}}) Update(ctx context.Context, req tfsdk.UpdateR {{- end}} name := {{.VarName}}Resource.Metadata.Name - {{.VarName}}Before, err := r.p.Client.{{.GetMethod}}({{if not .GetWithoutContext}}ctx, {{end}}name{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) + {{.VarName}}Before, err := r.p.Client.{{.GetMethod}}(ctx, name{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", err, "{{.Kind}}")) return @@ -328,7 +328,7 @@ func (r resourceTeleport{{.Name}}) Update(ctx context.Context, req tfsdk.UpdateR backoff := backoff.NewDecorr(r.p.RetryConfig.Base, r.p.RetryConfig.Cap, clockwork.NewRealClock()) for { tries = tries + 1 - {{.VarName}}I, err = r.p.Client.{{.GetMethod}}({{if not .GetWithoutContext}}ctx, {{end}}name{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) + {{.VarName}}I, err = r.p.Client.{{.GetMethod}}(ctx, name{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", err, "{{.Kind}}")) return @@ -394,7 +394,7 @@ func (r resourceTeleport{{.Name}}) Delete(ctx context.Context, req tfsdk.DeleteR // ImportState imports {{.Name}} state func (r resourceTeleport{{.Name}}) ImportState(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { - {{.VarName}}, err := r.p.Client.{{.GetMethod}}({{if not .GetWithoutContext}}ctx, {{end}}req.ID{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) + {{.VarName}}, err := r.p.Client.{{.GetMethod}}(ctx, req.ID{{if ne .WithSecrets ""}}, {{.WithSecrets}}{{end}}) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading {{.Name}}", trace.Wrap(err), "{{.Kind}}")) return diff --git a/terraform/provider/data_source_teleport_user.go b/terraform/provider/data_source_teleport_user.go index 8ca3d0617..b7621b933 100755 --- a/terraform/provider/data_source_teleport_user.go +++ b/terraform/provider/data_source_teleport_user.go @@ -60,7 +60,7 @@ func (r dataSourceTeleportUser) Read(ctx context.Context, req tfsdk.ReadDataSour return } - userI, err := r.p.Client.GetUser(id.Value, false) + userI, err := r.p.Client.GetUser(ctx, id.Value, false) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading User", trace.Wrap(err), "user")) return diff --git a/terraform/provider/resource_teleport_bot.go b/terraform/provider/resource_teleport_bot.go index 1c236ef3e..4a756bd88 100644 --- a/terraform/provider/resource_teleport_bot.go +++ b/terraform/provider/resource_teleport_bot.go @@ -20,14 +20,15 @@ import ( "context" "time" - "github.com/gravitational/teleport/api/client/proto" - "github.com/gravitational/teleport/api/types/wrappers" "github.com/gravitational/trace" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/gravitational/teleport/api/client/proto" + "github.com/gravitational/teleport/api/types/wrappers" + "github.com/gravitational/teleport-plugins/terraform/tfschema" ) @@ -210,7 +211,7 @@ func (r resourceTeleportBot) Read(ctx context.Context, req tfsdk.ReadResourceReq return } - _, err := r.p.Client.GetUser(plan.UserName.Value, false) + _, err := r.p.Client.GetUser(ctx, plan.UserName.Value, false) if trace.IsNotFound(err) { resp.State.RemoveResource(ctx) return diff --git a/terraform/provider/resource_teleport_github_connector.go b/terraform/provider/resource_teleport_github_connector.go index ca5e17a39..6742d1d9c 100755 --- a/terraform/provider/resource_teleport_github_connector.go +++ b/terraform/provider/resource_teleport_github_connector.go @@ -99,7 +99,7 @@ func (r resourceTeleportGithubConnector) Create(ctx context.Context, req tfsdk.C return } - err = r.p.Client.UpsertGithubConnector(ctx, githubConnectorResource) + _, err = r.p.Client.CreateGithubConnector(ctx, githubConnectorResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error creating GithubConnector", trace.Wrap(err), "github")) return @@ -230,7 +230,7 @@ func (r resourceTeleportGithubConnector) Update(ctx context.Context, req tfsdk.U return } - err = r.p.Client.UpsertGithubConnector(ctx, githubConnectorResource) + _, err = r.p.Client.UpsertGithubConnector(ctx, githubConnectorResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error updating GithubConnector", err, "github")) return diff --git a/terraform/provider/resource_teleport_oidc_connector.go b/terraform/provider/resource_teleport_oidc_connector.go index 6253f45c7..36d860b38 100755 --- a/terraform/provider/resource_teleport_oidc_connector.go +++ b/terraform/provider/resource_teleport_oidc_connector.go @@ -99,7 +99,7 @@ func (r resourceTeleportOIDCConnector) Create(ctx context.Context, req tfsdk.Cre return } - err = r.p.Client.UpsertOIDCConnector(ctx, oidcConnectorResource) + _, err = r.p.Client.CreateOIDCConnector(ctx, oidcConnectorResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error creating OIDCConnector", trace.Wrap(err), "oidc")) return @@ -230,7 +230,7 @@ func (r resourceTeleportOIDCConnector) Update(ctx context.Context, req tfsdk.Upd return } - err = r.p.Client.UpsertOIDCConnector(ctx, oidcConnectorResource) + _, err = r.p.Client.UpsertOIDCConnector(ctx, oidcConnectorResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error updating OIDCConnector", err, "oidc")) return diff --git a/terraform/provider/resource_teleport_role.go b/terraform/provider/resource_teleport_role.go index 81b0df7c9..0121c55cc 100755 --- a/terraform/provider/resource_teleport_role.go +++ b/terraform/provider/resource_teleport_role.go @@ -99,7 +99,7 @@ func (r resourceTeleportRole) Create(ctx context.Context, req tfsdk.CreateResour return } - err = r.p.Client.UpsertRole(ctx, roleResource) + _, err = r.p.Client.CreateRole(ctx, roleResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error creating Role", trace.Wrap(err), "role")) return @@ -230,7 +230,7 @@ func (r resourceTeleportRole) Update(ctx context.Context, req tfsdk.UpdateResour return } - err = r.p.Client.UpsertRole(ctx, roleResource) + _, err = r.p.Client.UpsertRole(ctx, roleResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error updating Role", err, "role")) return diff --git a/terraform/provider/resource_teleport_saml_connector.go b/terraform/provider/resource_teleport_saml_connector.go index e0d93cbb2..92548c5ce 100755 --- a/terraform/provider/resource_teleport_saml_connector.go +++ b/terraform/provider/resource_teleport_saml_connector.go @@ -99,7 +99,7 @@ func (r resourceTeleportSAMLConnector) Create(ctx context.Context, req tfsdk.Cre return } - err = r.p.Client.UpsertSAMLConnector(ctx, samlConnectorResource) + _, err = r.p.Client.CreateSAMLConnector(ctx, samlConnectorResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error creating SAMLConnector", trace.Wrap(err), "saml")) return @@ -230,7 +230,7 @@ func (r resourceTeleportSAMLConnector) Update(ctx context.Context, req tfsdk.Upd return } - err = r.p.Client.UpsertSAMLConnector(ctx, samlConnectorResource) + _, err = r.p.Client.UpsertSAMLConnector(ctx, samlConnectorResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error updating SAMLConnector", err, "saml")) return diff --git a/terraform/provider/resource_teleport_user.go b/terraform/provider/resource_teleport_user.go index ab68cd350..07afe5930 100755 --- a/terraform/provider/resource_teleport_user.go +++ b/terraform/provider/resource_teleport_user.go @@ -79,7 +79,7 @@ func (r resourceTeleportUser) Create(ctx context.Context, req tfsdk.CreateResour id := userResource.Metadata.Name - _, err = r.p.Client.GetUser(id, false) + _, err = r.p.Client.GetUser(ctx, id, false) if !trace.IsNotFound(err) { if err == nil { existErr := fmt.Sprintf("User exists in Teleport. Either remove it (tctl rm user/%v)"+ @@ -99,7 +99,7 @@ func (r resourceTeleportUser) Create(ctx context.Context, req tfsdk.CreateResour return } - err = r.p.Client.CreateUser(ctx, userResource) + _, err = r.p.Client.CreateUser(ctx, userResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error creating User", trace.Wrap(err), "user")) return @@ -111,7 +111,7 @@ func (r resourceTeleportUser) Create(ctx context.Context, req tfsdk.CreateResour backoff := backoff.NewDecorr(r.p.RetryConfig.Base, r.p.RetryConfig.Cap, clockwork.NewRealClock()) for { tries = tries + 1 - userI, err = r.p.Client.GetUser(id, false) + userI, err = r.p.Client.GetUser(ctx, id, false) if trace.IsNotFound(err) { if bErr := backoff.Do(ctx); bErr != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading User", trace.Wrap(err), "user")) @@ -170,7 +170,7 @@ func (r resourceTeleportUser) Read(ctx context.Context, req tfsdk.ReadResourceRe return } - userI, err := r.p.Client.GetUser(id.Value, false) + userI, err := r.p.Client.GetUser(ctx, id.Value, false) if trace.IsNotFound(err) { resp.State.RemoveResource(ctx) return @@ -224,13 +224,13 @@ func (r resourceTeleportUser) Update(ctx context.Context, req tfsdk.UpdateResour } name := userResource.Metadata.Name - userBefore, err := r.p.Client.GetUser(name, false) + userBefore, err := r.p.Client.GetUser(ctx, name, false) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading User", err, "user")) return } - err = r.p.Client.UpdateUser(ctx, userResource) + _, err = r.p.Client.UpsertUser(ctx, userResource) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error updating User", err, "user")) return @@ -243,7 +243,7 @@ func (r resourceTeleportUser) Update(ctx context.Context, req tfsdk.UpdateResour backoff := backoff.NewDecorr(r.p.RetryConfig.Base, r.p.RetryConfig.Cap, clockwork.NewRealClock()) for { tries = tries + 1 - userI, err = r.p.Client.GetUser(name, false) + userI, err = r.p.Client.GetUser(ctx, name, false) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading User", err, "user")) return @@ -301,7 +301,7 @@ func (r resourceTeleportUser) Delete(ctx context.Context, req tfsdk.DeleteResour // ImportState imports User state func (r resourceTeleportUser) ImportState(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) { - user, err := r.p.Client.GetUser(req.ID, false) + user, err := r.p.Client.GetUser(ctx, req.ID, false) if err != nil { resp.Diagnostics.Append(diagFromWrappedErr("Error reading User", trace.Wrap(err), "user")) return diff --git a/terraform/reference.mdx b/terraform/reference.mdx index eb8140739..34bfe429f 100755 --- a/terraform/reference.mdx +++ b/terraform/reference.mdx @@ -2290,6 +2290,7 @@ Specification of the device. | model_identifier | string | | | | os_build | string | | | | os_build_supplemental | string | | | +| os_id | string | | | | os_usernames | array of strings | | | | os_version | string | | | | update_time | RFC3339 time | | | diff --git a/terraform/tfschema/devicetrust/v1/device_terraform.go b/terraform/tfschema/devicetrust/v1/device_terraform.go index b241ce7f3..aeea45156 100644 --- a/terraform/tfschema/devicetrust/v1/device_terraform.go +++ b/terraform/tfschema/devicetrust/v1/device_terraform.go @@ -134,6 +134,11 @@ func GenSchemaDeviceV1(ctx context.Context) (github_com_hashicorp_terraform_plug Optional: true, Type: github_com_hashicorp_terraform_plugin_framework_types.StringType, }, + "os_id": { + Description: "", + Optional: true, + Type: github_com_hashicorp_terraform_plugin_framework_types.StringType, + }, "os_usernames": { Description: "", Optional: true, @@ -576,6 +581,23 @@ func CopyDeviceV1FromTerraform(_ context.Context, tf github_com_hashicorp_terraf } } } + { + a, ok := tf.Attrs["os_id"] + if !ok { + diags.Append(attrReadMissingDiag{"DeviceV1.spec.profile.os_id"}) + } else { + v, ok := a.(github_com_hashicorp_terraform_plugin_framework_types.String) + if !ok { + diags.Append(attrReadConversionFailureDiag{"DeviceV1.spec.profile.os_id", "github.com/hashicorp/terraform-plugin-framework/types.String"}) + } else { + var t string + if !v.Null && !v.Unknown { + t = string(v.Value) + } + obj.OsId = t + } + } + } } } } @@ -1186,6 +1208,28 @@ func CopyDeviceV1ToTerraform(ctx context.Context, obj *github_com_gravitational_ tf.Attrs["os_build_supplemental"] = v } } + { + t, ok := tf.AttrTypes["os_id"] + if !ok { + diags.Append(attrWriteMissingDiag{"DeviceV1.spec.profile.os_id"}) + } else { + v, ok := tf.Attrs["os_id"].(github_com_hashicorp_terraform_plugin_framework_types.String) + if !ok { + i, err := t.ValueFromTerraform(ctx, github_com_hashicorp_terraform_plugin_go_tftypes.NewValue(t.TerraformType(ctx), nil)) + if err != nil { + diags.Append(attrWriteGeneralError{"DeviceV1.spec.profile.os_id", err}) + } + v, ok = i.(github_com_hashicorp_terraform_plugin_framework_types.String) + if !ok { + diags.Append(attrWriteConversionFailureDiag{"DeviceV1.spec.profile.os_id", "github.com/hashicorp/terraform-plugin-framework/types.String"}) + } + v.Null = string(obj.OsId) == "" + } + v.Value = string(obj.OsId) + v.Unknown = false + tf.Attrs["os_id"] = v + } + } } v.Unknown = false tf.Attrs["profile"] = v