diff --git a/integrations/terraform/gen/plural_data_source.go.tpl b/integrations/terraform/gen/plural_data_source.go.tpl index 9325e187d67b2..744b02f4d0f6d 100644 --- a/integrations/terraform/gen/plural_data_source.go.tpl +++ b/integrations/terraform/gen/plural_data_source.go.tpl @@ -74,7 +74,21 @@ func (r dataSourceTeleport{{.Name}}) Read(ctx context.Context, req tfsdk.ReadDat return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + {{if .IsPlainStruct -}} {{.VarName}} := {{.VarName}}I {{else if .ConvertPackagePath -}} diff --git a/integrations/terraform/gen/singular_data_source.go.tpl b/integrations/terraform/gen/singular_data_source.go.tpl index 1f3acb818151f..dd0406e95b0af 100644 --- a/integrations/terraform/gen/singular_data_source.go.tpl +++ b/integrations/terraform/gen/singular_data_source.go.tpl @@ -59,7 +59,12 @@ func (r dataSourceTeleport{{.Name}}) Read(ctx context.Context, req tfsdk.ReadDat return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + {{if .IsPlainStruct -}} {{.VarName}} := {{.VarName}}I {{else -}} @@ -71,6 +76,15 @@ func (r dataSourceTeleport{{.Name}}) Read(ctx context.Context, req tfsdk.ReadDat return } + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = types.String{Value: {{.VarName}}.GetName()} + } + diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/integrations/terraform/provider/data_source_teleport_access_list.go b/integrations/terraform/provider/data_source_teleport_access_list.go index de49876d54e00..bd459947d8cb4 100755 --- a/integrations/terraform/provider/data_source_teleport_access_list.go +++ b/integrations/terraform/provider/data_source_teleport_access_list.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportAccessList) Read(ctx context.Context, req tfsdk.ReadDa return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + accessList := convert.ToProto(accessListI) diags = schemav1.CopyAccessListToTerraform(ctx, accessList, &state) diff --git a/integrations/terraform/provider/data_source_teleport_access_monitoring_rule.go b/integrations/terraform/provider/data_source_teleport_access_monitoring_rule.go index 08212625069c3..5c5b2d4a8d825 100755 --- a/integrations/terraform/provider/data_source_teleport_access_monitoring_rule.go +++ b/integrations/terraform/provider/data_source_teleport_access_monitoring_rule.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportAccessMonitoringRule) Read(ctx context.Context, req tf return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + accessMonitoringRule := accessMonitoringRuleI diags = schemav1.CopyAccessMonitoringRuleToTerraform(ctx, accessMonitoringRule, &state) diff --git a/integrations/terraform/provider/data_source_teleport_app.go b/integrations/terraform/provider/data_source_teleport_app.go index 235b0cb4c2df0..01eadadf2e294 100755 --- a/integrations/terraform/provider/data_source_teleport_app.go +++ b/integrations/terraform/provider/data_source_teleport_app.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportApp) Read(ctx context.Context, req tfsdk.ReadDataSourc return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + app := appI.(*apitypes.AppV3) diags = tfschema.CopyAppV3ToTerraform(ctx, app, &state) diff --git a/integrations/terraform/provider/data_source_teleport_auth_preference.go b/integrations/terraform/provider/data_source_teleport_auth_preference.go index f88e5af763fc4..5c5f2909f18ff 100755 --- a/integrations/terraform/provider/data_source_teleport_auth_preference.go +++ b/integrations/terraform/provider/data_source_teleport_auth_preference.go @@ -57,7 +57,12 @@ func (r dataSourceTeleportAuthPreference) Read(ctx context.Context, req tfsdk.Re return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + authPreference := authPreferenceI.(*apitypes.AuthPreferenceV2) diags := tfschema.CopyAuthPreferenceV2ToTerraform(ctx, authPreference, &state) resp.Diagnostics.Append(diags...) @@ -65,6 +70,15 @@ func (r dataSourceTeleportAuthPreference) Read(ctx context.Context, req tfsdk.Re return } + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = types.String{Value: authPreference.GetName()} + } + diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/integrations/terraform/provider/data_source_teleport_cluster_maintenance_config.go b/integrations/terraform/provider/data_source_teleport_cluster_maintenance_config.go index d34d8e98e5226..60b6fffd3ec2c 100755 --- a/integrations/terraform/provider/data_source_teleport_cluster_maintenance_config.go +++ b/integrations/terraform/provider/data_source_teleport_cluster_maintenance_config.go @@ -57,7 +57,12 @@ func (r dataSourceTeleportClusterMaintenanceConfig) Read(ctx context.Context, re return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + clusterMaintenanceConfig := clusterMaintenanceConfigI.(*apitypes.ClusterMaintenanceConfigV1) diags := tfschema.CopyClusterMaintenanceConfigV1ToTerraform(ctx, clusterMaintenanceConfig, &state) resp.Diagnostics.Append(diags...) @@ -65,6 +70,15 @@ func (r dataSourceTeleportClusterMaintenanceConfig) Read(ctx context.Context, re return } + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = types.String{Value: clusterMaintenanceConfig.GetName()} + } + diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/integrations/terraform/provider/data_source_teleport_cluster_networking_config.go b/integrations/terraform/provider/data_source_teleport_cluster_networking_config.go index f69da4b3a2fc0..2ae1dd90d97a9 100755 --- a/integrations/terraform/provider/data_source_teleport_cluster_networking_config.go +++ b/integrations/terraform/provider/data_source_teleport_cluster_networking_config.go @@ -57,7 +57,12 @@ func (r dataSourceTeleportClusterNetworkingConfig) Read(ctx context.Context, req return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + clusterNetworkingConfig := clusterNetworkingConfigI.(*apitypes.ClusterNetworkingConfigV2) diags := tfschema.CopyClusterNetworkingConfigV2ToTerraform(ctx, clusterNetworkingConfig, &state) resp.Diagnostics.Append(diags...) @@ -65,6 +70,15 @@ func (r dataSourceTeleportClusterNetworkingConfig) Read(ctx context.Context, req return } + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = types.String{Value: clusterNetworkingConfig.GetName()} + } + diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/integrations/terraform/provider/data_source_teleport_database.go b/integrations/terraform/provider/data_source_teleport_database.go index c9a1fa364eb7e..471e73c77f0b1 100755 --- a/integrations/terraform/provider/data_source_teleport_database.go +++ b/integrations/terraform/provider/data_source_teleport_database.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportDatabase) Read(ctx context.Context, req tfsdk.ReadData return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + database := databaseI.(*apitypes.DatabaseV3) diags = tfschema.CopyDatabaseV3ToTerraform(ctx, database, &state) diff --git a/integrations/terraform/provider/data_source_teleport_device_trust.go b/integrations/terraform/provider/data_source_teleport_device_trust.go index 72b0ac6dd10e6..a6b6e95eea87b 100755 --- a/integrations/terraform/provider/data_source_teleport_device_trust.go +++ b/integrations/terraform/provider/data_source_teleport_device_trust.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportDeviceV1) Read(ctx context.Context, req tfsdk.ReadData return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + trustedDevice := trustedDeviceI diags = schemav1.CopyDeviceV1ToTerraform(ctx, trustedDevice, &state) diff --git a/integrations/terraform/provider/data_source_teleport_github_connector.go b/integrations/terraform/provider/data_source_teleport_github_connector.go index 1997898500cb3..e1d349305d0a7 100755 --- a/integrations/terraform/provider/data_source_teleport_github_connector.go +++ b/integrations/terraform/provider/data_source_teleport_github_connector.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportGithubConnector) Read(ctx context.Context, req tfsdk.R return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + githubConnector := githubConnectorI.(*apitypes.GithubConnectorV3) diags = tfschema.CopyGithubConnectorV3ToTerraform(ctx, githubConnector, &state) diff --git a/integrations/terraform/provider/data_source_teleport_installer.go b/integrations/terraform/provider/data_source_teleport_installer.go index 293f3a1abb406..ac6b4cb3c1410 100755 --- a/integrations/terraform/provider/data_source_teleport_installer.go +++ b/integrations/terraform/provider/data_source_teleport_installer.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportInstaller) Read(ctx context.Context, req tfsdk.ReadDat return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + installer := installerI.(*apitypes.InstallerV1) diags = tfschema.CopyInstallerV1ToTerraform(ctx, installer, &state) diff --git a/integrations/terraform/provider/data_source_teleport_login_rule.go b/integrations/terraform/provider/data_source_teleport_login_rule.go index d92230ddc978d..49616cc216b53 100755 --- a/integrations/terraform/provider/data_source_teleport_login_rule.go +++ b/integrations/terraform/provider/data_source_teleport_login_rule.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportLoginRule) Read(ctx context.Context, req tfsdk.ReadDat return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + loginRule := loginRuleI diags = schemav1.CopyLoginRuleToTerraform(ctx, loginRule, &state) diff --git a/integrations/terraform/provider/data_source_teleport_oidc_connector.go b/integrations/terraform/provider/data_source_teleport_oidc_connector.go index 53c0d6e544b7f..35de643397a22 100755 --- a/integrations/terraform/provider/data_source_teleport_oidc_connector.go +++ b/integrations/terraform/provider/data_source_teleport_oidc_connector.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportOIDCConnector) Read(ctx context.Context, req tfsdk.Rea return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + oidcConnector := oidcConnectorI.(*apitypes.OIDCConnectorV3) diags = tfschema.CopyOIDCConnectorV3ToTerraform(ctx, oidcConnector, &state) diff --git a/integrations/terraform/provider/data_source_teleport_okta_import_rule.go b/integrations/terraform/provider/data_source_teleport_okta_import_rule.go index c5561b9140717..ecd5066ac6b3c 100755 --- a/integrations/terraform/provider/data_source_teleport_okta_import_rule.go +++ b/integrations/terraform/provider/data_source_teleport_okta_import_rule.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportOktaImportRule) Read(ctx context.Context, req tfsdk.Re return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + oktaImportRule := oktaImportRuleI.(*apitypes.OktaImportRuleV1) diags = tfschema.CopyOktaImportRuleV1ToTerraform(ctx, oktaImportRule, &state) diff --git a/integrations/terraform/provider/data_source_teleport_provision_token.go b/integrations/terraform/provider/data_source_teleport_provision_token.go index e3cfac07bea41..935b170869efd 100755 --- a/integrations/terraform/provider/data_source_teleport_provision_token.go +++ b/integrations/terraform/provider/data_source_teleport_provision_token.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportProvisionToken) Read(ctx context.Context, req tfsdk.Re return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + provisionToken := provisionTokenI.(*apitypes.ProvisionTokenV2) diags = token.CopyProvisionTokenV2ToTerraform(ctx, provisionToken, &state) diff --git a/integrations/terraform/provider/data_source_teleport_role.go b/integrations/terraform/provider/data_source_teleport_role.go index 283b70ccce216..1a90e380004dc 100755 --- a/integrations/terraform/provider/data_source_teleport_role.go +++ b/integrations/terraform/provider/data_source_teleport_role.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportRole) Read(ctx context.Context, req tfsdk.ReadDataSour return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + role := roleI.(*apitypes.RoleV6) diags = tfschema.CopyRoleV6ToTerraform(ctx, role, &state) diff --git a/integrations/terraform/provider/data_source_teleport_saml_connector.go b/integrations/terraform/provider/data_source_teleport_saml_connector.go index 6536b68384d24..47eb87d9cfe18 100755 --- a/integrations/terraform/provider/data_source_teleport_saml_connector.go +++ b/integrations/terraform/provider/data_source_teleport_saml_connector.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportSAMLConnector) Read(ctx context.Context, req tfsdk.Rea return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + samlConnector := samlConnectorI.(*apitypes.SAMLConnectorV2) diags = tfschema.CopySAMLConnectorV2ToTerraform(ctx, samlConnector, &state) diff --git a/integrations/terraform/provider/data_source_teleport_server.go b/integrations/terraform/provider/data_source_teleport_server.go index 90044a6651bcc..56f6659a9fb7e 100755 --- a/integrations/terraform/provider/data_source_teleport_server.go +++ b/integrations/terraform/provider/data_source_teleport_server.go @@ -66,7 +66,21 @@ func (r dataSourceTeleportServer) Read(ctx context.Context, req tfsdk.ReadDataSo return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + server := serverI.(*apitypes.ServerV2) diags = tfschema.CopyServerV2ToTerraform(ctx, server, &state) diff --git a/integrations/terraform/provider/data_source_teleport_session_recording_config.go b/integrations/terraform/provider/data_source_teleport_session_recording_config.go index f15cb6d0cff86..df33eafe06788 100755 --- a/integrations/terraform/provider/data_source_teleport_session_recording_config.go +++ b/integrations/terraform/provider/data_source_teleport_session_recording_config.go @@ -57,7 +57,12 @@ func (r dataSourceTeleportSessionRecordingConfig) Read(ctx context.Context, req return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + sessionRecordingConfig := sessionRecordingConfigI.(*apitypes.SessionRecordingConfigV2) diags := tfschema.CopySessionRecordingConfigV2ToTerraform(ctx, sessionRecordingConfig, &state) resp.Diagnostics.Append(diags...) @@ -65,6 +70,15 @@ func (r dataSourceTeleportSessionRecordingConfig) Read(ctx context.Context, req return } + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = types.String{Value: sessionRecordingConfig.GetName()} + } + diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/integrations/terraform/provider/data_source_teleport_static_host_user.go b/integrations/terraform/provider/data_source_teleport_static_host_user.go index f8b59df73c963..37e1c51090a84 100755 --- a/integrations/terraform/provider/data_source_teleport_static_host_user.go +++ b/integrations/terraform/provider/data_source_teleport_static_host_user.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportStaticHostUser) Read(ctx context.Context, req tfsdk.Re return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + staticHostUser := staticHostUserI diags = schemav1.CopyStaticHostUserToTerraform(ctx, staticHostUser, &state) diff --git a/integrations/terraform/provider/data_source_teleport_trusted_cluster.go b/integrations/terraform/provider/data_source_teleport_trusted_cluster.go index 50d42c3967deb..6d3fa7e496fcd 100755 --- a/integrations/terraform/provider/data_source_teleport_trusted_cluster.go +++ b/integrations/terraform/provider/data_source_teleport_trusted_cluster.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportTrustedCluster) Read(ctx context.Context, req tfsdk.Re return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + trustedCluster := trustedClusterI.(*apitypes.TrustedClusterV2) diags = tfschema.CopyTrustedClusterV2ToTerraform(ctx, trustedCluster, &state) diff --git a/integrations/terraform/provider/data_source_teleport_user.go b/integrations/terraform/provider/data_source_teleport_user.go index ba0ee06998a3e..abee4d4336d72 100755 --- a/integrations/terraform/provider/data_source_teleport_user.go +++ b/integrations/terraform/provider/data_source_teleport_user.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportUser) Read(ctx context.Context, req tfsdk.ReadDataSour return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + user := userI.(*apitypes.UserV2) diags = tfschema.CopyUserV2ToTerraform(ctx, user, &state) diff --git a/integrations/terraform/provider/data_source_teleport_workload_identity.go b/integrations/terraform/provider/data_source_teleport_workload_identity.go index 1b1d15fb99dcd..7f4c2704d987a 100755 --- a/integrations/terraform/provider/data_source_teleport_workload_identity.go +++ b/integrations/terraform/provider/data_source_teleport_workload_identity.go @@ -65,7 +65,21 @@ func (r dataSourceTeleportWorkloadIdentity) Read(ctx context.Context, req tfsdk. return } - var state types.Object + var state types.Object + resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + // Todo: Remove after updating terraform-plugin to >=v1.5.0. + // terraform-plugin-testing version <1.5.0 requires data resources to + // implement the 'id' attribute. + // https://developer.hashicorp.com/terraform/plugin/framework/acctests#no-id-found-in-attributes + v, ok := state.Attrs["id"] + if !ok || v.IsNull() { + state.Attrs["id"] = id + } + workloadIdentity := workloadIdentityI diags = schemav1.CopyWorkloadIdentityToTerraform(ctx, workloadIdentity, &state) diff --git a/integrations/terraform/testlib/cluster_networking_config_test.go b/integrations/terraform/testlib/cluster_networking_config_test.go index ac3750b45b815..fbcb118e0f5d3 100644 --- a/integrations/terraform/testlib/cluster_networking_config_test.go +++ b/integrations/terraform/testlib/cluster_networking_config_test.go @@ -27,6 +27,25 @@ import ( "github.com/gravitational/teleport/api/types" ) +func (s *TerraformSuiteOSS) TestClusterNetworkingConfigDataSource() { + name := "data.teleport_cluster_networking_config.test" + + resource.Test(s.T(), resource.TestCase{ + ProtoV6ProviderFactories: s.terraformProviders, + IsUnitTest: true, + Steps: []resource.TestStep{ + { + Config: s.getFixture("networking_config_data_source.tf"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(name, "kind", "cluster_networking_config"), + resource.TestCheckResourceAttr(name, "version", "v2"), + resource.TestCheckResourceAttr(name, "id", "cluster-networking-config"), + ), + }, + }, + }) +} + func (s *TerraformSuiteOSS) TestClusterNetworkingConfig() { name := "teleport_cluster_networking_config.test" diff --git a/integrations/terraform/testlib/fixtures/networking_config_data_source.tf b/integrations/terraform/testlib/fixtures/networking_config_data_source.tf new file mode 100644 index 0000000000000..ef6ecea3b95a4 --- /dev/null +++ b/integrations/terraform/testlib/fixtures/networking_config_data_source.tf @@ -0,0 +1,4 @@ +data "teleport_cluster_networking_config" "test" { + version = "v2" + kind = "cluster_networking_config" +} diff --git a/integrations/terraform/testlib/fixtures/role_data_source.tf b/integrations/terraform/testlib/fixtures/role_data_source.tf new file mode 100644 index 0000000000000..fb9f58832bb8e --- /dev/null +++ b/integrations/terraform/testlib/fixtures/role_data_source.tf @@ -0,0 +1,7 @@ +data "teleport_role" "test" { + kind = "role" + version = "v7" + metadata = { + name = "test" + } +} diff --git a/integrations/terraform/testlib/role_test.go b/integrations/terraform/testlib/role_test.go index c7537fce075a0..8ee7f02351fd0 100644 --- a/integrations/terraform/testlib/role_test.go +++ b/integrations/terraform/testlib/role_test.go @@ -30,6 +30,48 @@ import ( "github.com/gravitational/teleport/api/types" ) +func (s *TerraformSuiteOSS) TestRoleDataSource() { + ctx, cancel := context.WithCancel(context.Background()) + s.T().Cleanup(cancel) + + checkDestroyed := func(state *terraform.State) error { + _, err := s.client.GetRole(ctx, "test") + if trace.IsNotFound(err) { + return nil + } + + return err + } + + role := &types.RoleV6{ + Metadata: types.Metadata{ + Name: "test", + }, + } + err := role.CheckAndSetDefaults() + require.NoError(s.T(), err) + + _, err = s.client.UpsertRole(ctx, role) + require.NoError(s.T(), err) + + name := "data.teleport_role.test" + + resource.Test(s.T(), resource.TestCase{ + ProtoV6ProviderFactories: s.terraformProviders, + CheckDestroy: checkDestroyed, + Steps: []resource.TestStep{ + { + Config: s.getFixture("role_data_source.tf"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(name, "kind", "role"), + resource.TestCheckResourceAttr(name, "version", "v7"), + resource.TestCheckResourceAttr(name, "metadata.name", "test"), + ), + }, + }, + }) +} + func (s *TerraformSuiteOSS) TestRole() { ctx, cancel := context.WithCancel(context.Background()) s.T().Cleanup(cancel)