Skip to content

Commit

Permalink
Partial work on issue #25
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-r-west committed Feb 8, 2022
1 parent 2474492 commit b858eb6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 294 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: Release
on:
push:
tags:
- 'v0.0.1-alpha*'
- 'v0.0.*'
jobs:
goreleaser:
runs-on: ubuntu-latest
Expand Down
68 changes: 0 additions & 68 deletions internal/provider/data_source_epcc_realm.go

This file was deleted.

2 changes: 0 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func New(version string) func() *schema.Provider {
"epcc_product": dataSourceEpccProduct(),
"epcc_product_price": dataSourceEpccProductPrice(),
"epcc_promotion": dataSourceEpccPromotion(),
"epcc_realm": dataSourceEpccRealm(),
"epcc_profile": dataSourceEpccProfile(),
"epcc_user_authentication_info": dataSourceEpccUserAuthenticationInfo(),
"epcc_account_authentication_settings": dataSourceAccountAuthenticationSettings(),
Expand Down Expand Up @@ -146,7 +145,6 @@ func New(version string) func() *schema.Provider {
"epcc_product": resourceEpccProduct(),
"epcc_product_price": resourceEpccProductPrice(),
"epcc_promotion": resourceEpccPromotion(),
"epcc_realm": resourceEpccRealm(),
"epcc_profile": resourceEpccProfile(),
"epcc_user_authentication_info": resourceEpccUserAuthenticationInfo(),
"epcc_settings": resourceEpccSettings(),
Expand Down
63 changes: 30 additions & 33 deletions internal/provider/resource_epcc_authentication_realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func resourceEpccAuthenticationRealm() *schema.Resource {
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Required: true,
Description: "The unique identifier for the authentication realm.",
},
"name": {
Expand All @@ -41,12 +41,12 @@ func resourceEpccAuthenticationRealm() *schema.Resource {
},
"origin_id": {
Type: schema.TypeString,
Required: true,
Computed: true,
Description: "The ID of the origin entity.",
},
"origin_type": {
Type: schema.TypeString,
Required: true,
Computed: true,
Description: "The type of the origin entity.",
},
},
Expand All @@ -55,15 +55,6 @@ func resourceEpccAuthenticationRealm() *schema.Resource {
}

func resourceEpccAuthenticationRealmDelete(ctx context.Context, d *schema.ResourceData, m interface{}) {
client := m.(*epcc.Client)
authenticationRealmId := d.Id()

err := epcc.Realms.Delete(&ctx, client, authenticationRealmId)

if err != nil {
ReportAPIError(ctx, err)
}

d.SetId("")
}

Expand Down Expand Up @@ -134,29 +125,35 @@ func resourceEpccAuthenticationRealmRead(ctx context.Context, d *schema.Resource
}

func resourceEpccAuthenticationRealmCreate(ctx context.Context, d *schema.ResourceData, m interface{}) {

client := m.(*epcc.Client)
authenticationRealm := &epcc.Realm{
Type: "authentication-realm",
Id: d.Get("id").(string),
Name: d.Get("name").(string),
RedirectUris: d.Get("redirect_uris").([]interface{}),
DuplicateEmailPolicy: d.Get("duplicate_email_policy").(string),
Relationships: &epcc.RealmRelationships{
Origin: &epcc.RealmRelationshipsOrigin{
Data: &epcc.RealmRelationshipsOriginData{
Id: d.Get("origin_id").(string),
Type: d.Get("origin_type").(string),
},
},
},
}
createAuthenticationRealmData, apiError := epcc.Realms.Create(&ctx, client, authenticationRealm)
if apiError != nil {
ReportAPIError(ctx, apiError)
realmId := d.Get("id").(string)

authenticationRealm, err := epcc.Realms.Get(&ctx, client, realmId)

if err != nil {
ReportAPIError(ctx, err)
return
}

d.SetId(createAuthenticationRealmData.Data.Id)

resourceEpccAuthenticationRealmRead(ctx, d, m)
if err := d.Set("name", authenticationRealm.Data.Name); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}
if err := d.Set("redirect_uris", authenticationRealm.Data.RedirectUris); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}
if err := d.Set("duplicate_email_policy", authenticationRealm.Data.DuplicateEmailPolicy); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}
if err := d.Set("origin_id", authenticationRealm.Data.Relationships.Origin.Data.Id); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}
if err := d.Set("origin_type", authenticationRealm.Data.Relationships.Origin.Data.Type); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}
}
26 changes: 16 additions & 10 deletions internal/provider/resource_epcc_authentication_realm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ func TestAccResourceAuthenticationRealm(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccResourceAuthenticationRealm,
{ // language=HCL
Config: `
data "epcc_customer_authentication_settings" "customer_auth_settings" {
}
resource "epcc_authentication_realm" "acc_test_realm" {
id = data.epcc_customer_authentication_settings.customer_auth_settings.realm_id
name = "test_realm"
redirect_uris = [
"https://google.com/"]
duplicate_email_policy = "allowed"
origin_id = "hello-world"
origin_type = "customer-authentication-settings"
}`,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("epcc_authentication_realm.acc_test_realm", "name", regexp.MustCompile("test_realm")),
resource.TestMatchResourceAttr("epcc_authentication_realm.acc_test_realm", "redirect_uris.#", regexp.MustCompile("1")),
Expand All @@ -29,12 +42,5 @@ func TestAccResourceAuthenticationRealm(t *testing.T) {

// language=HCL
const testAccResourceAuthenticationRealm = `
resource "epcc_authentication_realm" "acc_test_realm" {
name = "test_realm"
redirect_uris = [
"https://google.com/"]
duplicate_email_policy = "allowed"
origin_id = "hello-world"
origin_type = "customer-authentication-settings"
}
`
140 changes: 0 additions & 140 deletions internal/provider/resource_epcc_realm.go

This file was deleted.

Loading

0 comments on commit b858eb6

Please sign in to comment.