diff --git a/zitadel/application_api/application_api_test_dep/dependency.go b/zitadel/application_api/application_api_test_dep/dependency.go index 856f860f..16f0be49 100644 --- a/zitadel/application_api/application_api_test_dep/dependency.go +++ b/zitadel/application_api/application_api_test_dep/dependency.go @@ -10,13 +10,15 @@ import ( "github.com/zitadel/terraform-provider-zitadel/zitadel/helper/test_utils" ) -func Create(t *testing.T, frame *test_utils.OrgTestFrame, projectID, name string) (string, string) { - return test_utils.CreateDefaultDependency(t, "zitadel_application_api", application_api.AppIDVar, func() (string, error) { +func Create(t *testing.T, frame *test_utils.OrgTestFrame, projectID, name string) (template, id, clientID string) { + template, id = test_utils.CreateDefaultDependency(t, "zitadel_application_api", application_api.AppIDVar, func() (string, error) { apiApp, err := frame.AddAPIApp(frame, &management.AddAPIAppRequest{ ProjectId: projectID, Name: name, AuthMethodType: app.APIAuthMethodType_API_AUTH_METHOD_TYPE_PRIVATE_KEY_JWT, }) + clientID = apiApp.GetClientId() return apiApp.GetAppId(), err }) + return template, id, clientID } diff --git a/zitadel/application_api/datasource.go b/zitadel/application_api/datasource.go index c6207f0a..365dc08b 100644 --- a/zitadel/application_api/datasource.go +++ b/zitadel/application_api/datasource.go @@ -34,6 +34,12 @@ func GetDatasource() *schema.Resource { Computed: true, Description: "Auth method type", }, + ClientIDVar: { + Type: schema.TypeString, + Computed: true, + Description: "generated ID for this config", + Sensitive: true, + }, }, ReadContext: read, } diff --git a/zitadel/application_api/datasource_test.go b/zitadel/application_api/datasource_test.go index a32c6863..1880798c 100644 --- a/zitadel/application_api/datasource_test.go +++ b/zitadel/application_api/datasource_test.go @@ -22,7 +22,7 @@ func TestAccApplicationAPIDatasource_ID(t *testing.T) { exampleID := test_utils.AttributeValue(t, application_api.AppIDVar, attributes).AsString() projectDep, projectID := project_test_dep.Create(t, frame, frame.UniqueResourcesID) appName := "application_api_datasource_" + frame.UniqueResourcesID - _, appID := application_api_test_dep.Create(t, frame, projectID, appName) + _, appID, clientID := application_api_test_dep.Create(t, frame, projectID, appName) config = strings.Replace(config, exampleID, appID, 1) test_utils.RunDatasourceTest( t, @@ -35,6 +35,7 @@ func TestAccApplicationAPIDatasource_ID(t *testing.T) { "project_id": projectID, "app_id": appID, "name": appName, + "client_id": clientID, }, ) } @@ -50,7 +51,7 @@ func TestAccApplicationAPIsDatasources_ID_Name_Match(t *testing.T) { config = strings.Join(strings.Split(config, "\n")[0:6], "\n") config = strings.Replace(config, exampleName, appName, 1) projectDep, projectID := project_test_dep.Create(t, frame, frame.UniqueResourcesID) - _, appID := application_api_test_dep.Create(t, frame, projectID, appName) + _, appID, _ := application_api_test_dep.Create(t, frame, projectID, appName) test_utils.RunDatasourceTest( t, frame.BaseTestFrame, @@ -75,7 +76,7 @@ func TestAccApplicationAPIsDatasources_ID_Name_Mismatch(t *testing.T) { config = strings.Join(strings.Split(config, "\n")[0:6], "\n") config = strings.Replace(config, exampleName, "mismatch", 1) projectDep, projectID := project_test_dep.Create(t, frame, frame.UniqueResourcesID) - _, appID := application_api_test_dep.Create(t, frame, projectID, appName) + _, appID, _ := application_api_test_dep.Create(t, frame, projectID, appName) test_utils.RunDatasourceTest( t, frame.BaseTestFrame, diff --git a/zitadel/application_api/funcs.go b/zitadel/application_api/funcs.go index 4ac4e63c..ac66146f 100644 --- a/zitadel/application_api/funcs.go +++ b/zitadel/application_api/funcs.go @@ -137,6 +137,7 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn helper.OrgIDVar: app.GetDetails().GetResourceOwner(), NameVar: app.GetName(), authMethodTypeVar: api.GetAuthMethodType().String(), + ClientIDVar: api.GetClientId(), } for k, v := range set { if err := d.Set(k, v); err != nil { diff --git a/zitadel/application_key/resource_test.go b/zitadel/application_key/resource_test.go index e11517d2..5efe9409 100644 --- a/zitadel/application_key/resource_test.go +++ b/zitadel/application_key/resource_test.go @@ -21,7 +21,7 @@ func TestAccAppKey(t *testing.T) { exampleProperty := test_utils.AttributeValue(t, application_key.ExpirationDateVar, exampleAttributes).AsString() updatedProperty := "2501-01-01T08:45:00Z" projectDep, projectID := project_test_dep.Create(t, frame, frame.UniqueResourcesID) - appDep, appID := application_api_test_dep.Create(t, frame, projectID, frame.UniqueResourcesID) + appDep, appID, _ := application_api_test_dep.Create(t, frame, projectID, frame.UniqueResourcesID) test_utils.RunLifecyleTest( t, frame.BaseTestFrame, diff --git a/zitadel/application_oidc/application_oidc_test_dep/dependency.go b/zitadel/application_oidc/application_oidc_test_dep/dependency.go index 672410c8..d8e0d4a8 100644 --- a/zitadel/application_oidc/application_oidc_test_dep/dependency.go +++ b/zitadel/application_oidc/application_oidc_test_dep/dependency.go @@ -9,12 +9,14 @@ import ( "github.com/zitadel/terraform-provider-zitadel/zitadel/helper/test_utils" ) -func Create(t *testing.T, frame *test_utils.OrgTestFrame, projectID, name string) (string, string) { - return test_utils.CreateDefaultDependency(t, "zitadel_application_oidc", application_oidc.AppIDVar, func() (string, error) { +func Create(t *testing.T, frame *test_utils.OrgTestFrame, projectID, name string) (template string, id string, clientId string) { + template, id = test_utils.CreateDefaultDependency(t, "zitadel_application_oidc", application_oidc.AppIDVar, func() (string, error) { oidcApp, err := frame.AddOIDCApp(frame, &management.AddOIDCAppRequest{ ProjectId: projectID, Name: name, }) + clientId = oidcApp.GetClientId() return oidcApp.GetAppId(), err }) + return template, id, clientId } diff --git a/zitadel/application_oidc/datasource.go b/zitadel/application_oidc/datasource.go index 3d715d34..e28b4e61 100644 --- a/zitadel/application_oidc/datasource.go +++ b/zitadel/application_oidc/datasource.go @@ -114,6 +114,12 @@ func GetDatasource() *schema.Resource { Computed: true, Description: "Additional origins", }, + ClientIDVar: { + Type: schema.TypeString, + Computed: true, + Description: "Client ID", + Sensitive: true, + }, }, ReadContext: read, } diff --git a/zitadel/application_oidc/datasource_test.go b/zitadel/application_oidc/datasource_test.go index 5e188acc..e4bfb41e 100644 --- a/zitadel/application_oidc/datasource_test.go +++ b/zitadel/application_oidc/datasource_test.go @@ -22,7 +22,7 @@ func TestAccApplicationOIDCDatasource_ID(t *testing.T) { exampleID := test_utils.AttributeValue(t, application_oidc.AppIDVar, attributes).AsString() projectDep, projectID := project_test_dep.Create(t, frame, frame.UniqueResourcesID) appName := "application_oidc_datasource_" + frame.UniqueResourcesID - _, appID := application_oidc_test_dep.Create(t, frame, projectID, appName) + _, appID, clientID := application_oidc_test_dep.Create(t, frame, projectID, appName) config = strings.Replace(config, exampleID, appID, 1) test_utils.RunDatasourceTest( t, @@ -35,6 +35,7 @@ func TestAccApplicationOIDCDatasource_ID(t *testing.T) { "project_id": projectID, "app_id": appID, "name": appName, + "client_id": clientID, }, ) } @@ -50,7 +51,7 @@ func TestAccApplicationOIDCsDatasources_ID_Name_Match(t *testing.T) { config = strings.Join(strings.Split(config, "\n")[0:6], "\n") config = strings.Replace(config, exampleName, appName, 1) projectDep, projectID := project_test_dep.Create(t, frame, frame.UniqueResourcesID) - _, appID := application_oidc_test_dep.Create(t, frame, projectID, appName) + _, appID, _ := application_oidc_test_dep.Create(t, frame, projectID, appName) test_utils.RunDatasourceTest( t, frame.BaseTestFrame, @@ -75,7 +76,7 @@ func TestAccApplicationOIDCsDatasources_ID_Name_Mismatch(t *testing.T) { config = strings.Join(strings.Split(config, "\n")[0:6], "\n") config = strings.Replace(config, exampleName, "mismatch", 1) projectDep, projectID := project_test_dep.Create(t, frame, frame.UniqueResourcesID) - _, appID := application_oidc_test_dep.Create(t, frame, projectID, appName) + _, appID, _ := application_oidc_test_dep.Create(t, frame, projectID, appName) test_utils.RunDatasourceTest( t, frame.BaseTestFrame, diff --git a/zitadel/application_oidc/funcs.go b/zitadel/application_oidc/funcs.go index d961eb5a..9a5020c3 100644 --- a/zitadel/application_oidc/funcs.go +++ b/zitadel/application_oidc/funcs.go @@ -233,6 +233,7 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn idTokenUserinfoAssertionVar: oidc.GetIdTokenUserinfoAssertion(), clockSkewVar: clockSkew, additionalOriginsVar: oidc.GetAdditionalOrigins(), + ClientIDVar: oidc.GetClientId(), } for k, v := range set { if err := d.Set(k, v); err != nil {