Skip to content

Commit

Permalink
client id api
Browse files Browse the repository at this point in the history
  • Loading branch information
eliobischof committed May 31, 2024
1 parent f50801e commit 6c1432c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions zitadel/application_api/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
7 changes: 4 additions & 3 deletions zitadel/application_api/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,6 +35,7 @@ func TestAccApplicationAPIDatasource_ID(t *testing.T) {
"project_id": projectID,
"app_id": appID,
"name": appName,
"client_id": clientID,
},
)
}
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions zitadel/application_api/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion zitadel/application_key/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions zitadel/application_oidc/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func GetDatasource() *schema.Resource {
Type: schema.TypeString,
Computed: true,
Description: "Client ID",
Sensitive: true,
},
},
ReadContext: read,
Expand Down

0 comments on commit 6c1432c

Please sign in to comment.