-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add codefresh_idp and codefresh_account_idp resource and codefr…
…esh_account_idp datasource (#138) ## What Add codefresh_idp and codefresh_account_idp resource and codefresh_account_idp datasource ## Why New resources for identity providers ## Notes <!-- Add any notes here --> ## Checklist * [ ] _I have read [CONTRIBUTING.md](https://github.com/codefresh-io/terraform-provider-codefresh/blob/master/CONTRIBUTING.md)._ * [ ] _I have [allowed changes to my fork to be made](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)._ * [ ] _I have added tests, assuming new tests are warranted_. * [ ] _I understand that the `/test` comment will be ignored by the CI trigger [unless it is made by a repo admin or collaborator](https://codefresh.io/docs/docs/pipelines/triggers/git-triggers/#support-for-building-pull-requests-from-forks)._ --------- Co-authored-by: Yonatan Koren <[email protected]>
- Loading branch information
1 parent
c2313c5
commit 44cd0e2
Showing
17 changed files
with
2,549 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package codefresh | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAccountIdp() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "This data source retrieves an account level identity provider", | ||
Read: dataSourceAccountIdpRead, | ||
Schema: AccountIdpSchema(), | ||
} | ||
} | ||
|
||
// IdpSchema - | ||
func AccountIdpSchema() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ExactlyOneOf: []string{"_id", "client_name"}, | ||
}, | ||
"client_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ExactlyOneOf: []string{"_id", "client_name"}, | ||
}, | ||
"display_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"client_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"redirect_url": { | ||
Description: "API Callback url for the identity provider", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"redirect_ui_url": { | ||
Description: "UI Callback url for the identity provider", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"login_url": { | ||
Description: "Login url using the IDP to Codefresh", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAccountIdpRead(d *schema.ResourceData, meta interface{}) error { | ||
|
||
client := meta.(*cfclient.Client) | ||
|
||
idps, err := client.GetAccountIDPs() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_id, _idOk := d.GetOk("_id") | ||
clientName, clientNameOk := d.GetOk("client_name") | ||
|
||
for _, idp := range *idps { | ||
if clientNameOk && clientName.(string) != idp.ClientName { | ||
continue | ||
} | ||
if _idOk && _id.(string) != idp.ID { | ||
continue | ||
} | ||
|
||
err = mapDataAccountIdpToResource(idp, d) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if d.Id() == "" { | ||
return fmt.Errorf("[EROOR] Idp wasn't found") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func mapDataAccountIdpToResource(cfClientIDP cfclient.IDP, d *schema.ResourceData) error { | ||
|
||
d.SetId(cfClientIDP.ID) | ||
d.Set("client_name", cfClientIDP.ClientName) | ||
d.Set("client_type", cfClientIDP.ClientType) | ||
d.Set("display_name", cfClientIDP.DisplayName) | ||
d.Set("redirect_url", cfClientIDP.RedirectUrl) | ||
d.Set("redirect_ui_url", cfClientIDP.RedirectUiUrl) | ||
d.Set("login_url", cfClientIDP.LoginUrl) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package idp is shared by idp-related resources. | ||
package idp |
Oops, something went wrong.