Skip to content

Commit

Permalink
feat(security-email): working creation
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Wasilewski <[email protected]>
  • Loading branch information
mwasilew2 committed Jan 15, 2024
1 parent 92b9c5e commit 748a40e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion spacelift/internal/structs/security_email.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package structs

type SecurityEmail struct {
Email string `json:"email"`
Email string `graphql:"email"`
}
11 changes: 5 additions & 6 deletions spacelift/resource_security_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ func resourceSecurityEmail() *schema.Resource {

func resourceSecurityEmailCreate(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
var mutation struct {
SecurityEmail *structs.SecurityEmail `graphql:"accountUpdateSecurityEmail(securityEmail: $email)"`
}
variables := map[string]interface{}{
"email": toString(data.Get("email")),
SecurityEmail *string `graphql:"accountUpdateSecurityEmail(securityEmail: $securityEmail)"`
}

variables := map[string]interface{}{"securityEmail": toString(data.Get("email"))}
if err := i.(*internal.Client).Mutate(ctx, "AccountUpdateSecurityEmail", &mutation, variables); err != nil {
return diag.Errorf("could not create security email: %v", err)
}
Expand All @@ -65,14 +64,14 @@ func resourceSecurityEmailRead(ctx context.Context, data *schema.ResourceData, i
return nil
}

data.Set("email", query.SecurityEmail.Email)
data.Set("email", query.SecurityEmail)

return nil
}

func resourceSecurityEmailUpdate(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
var mutation struct {
SecurityEmail *structs.SecurityEmail `graphql:"accountUpdateSecurityEmail(securityEmail: $email)"`
SecurityEmail *string `graphql:"accountUpdateSecurityEmail(securityEmail: $email)"`
}
variables := map[string]interface{}{
"email": toString(data.Get("email")),
Expand Down
38 changes: 38 additions & 0 deletions spacelift/resource_security_email_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package spacelift

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

. "github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/testhelpers"
)

var securityEmailSimple = `
resource "spacelift_security_email" "test" {
email = "%s"
}
`

func Test_resourceSecurityEmail(t *testing.T) {
const resourceName = "spacelift_resource_security_email.test"

t.Run("creates a security email without an error", func(t *testing.T) {
exampleEmail := "[email protected]"
testSteps(t, []resource.TestStep{
{
Config: fmt.Sprintf(securityEmailSimple, exampleEmail),
Check: Resource(
resourceName,
Attribute("email", Equals(exampleEmail)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
})
})
}

0 comments on commit 748a40e

Please sign in to comment.