-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Creating dedicated resource definition for sfx_team
#509
Merged
MovieStoreGuy
merged 2 commits into
splunk-terraform:main
from
MovieStoreGuy:msg/port-team-resource
Oct 8, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/splunk-terraform/terraform-provider-signalfx | ||
|
||
go 1.21 | ||
go 1.23 | ||
|
||
toolchain go1.23.2 | ||
|
||
|
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,145 @@ | ||
package team | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/signalfx/signalfx-go/team" | ||
|
||
pmeta "github.com/splunk-terraform/terraform-provider-signalfx/internal/providermeta" | ||
) | ||
|
||
const ( | ||
ResourceName = "signalfx_team" | ||
AppPath = "/team" | ||
) | ||
|
||
func NewResource() *schema.Resource { | ||
return &schema.Resource{ | ||
SchemaFunc: newSchema, | ||
SchemaVersion: 1, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
CreateContext: newResourceCreate(), | ||
ReadContext: newResourceRead(), | ||
UpdateContext: newResourceUpdate(), | ||
DeleteContext: newResourceDelete(), | ||
} | ||
} | ||
|
||
func newResourceCreate() schema.CreateContextFunc { | ||
return func(ctx context.Context, rd *schema.ResourceData, meta any) diag.Diagnostics { | ||
payload, err := decodeTerraform(rd) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
client, err := pmeta.LoadClient(ctx, meta) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
tm, err := client.CreateTeam(ctx, &team.CreateUpdateTeamRequest{ | ||
Name: payload.Name, | ||
Description: payload.Description, | ||
Members: payload.Members, | ||
NotificationLists: payload.NotificationLists, | ||
}) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
tflog.Debug(ctx, "Created new team", map[string]any{ | ||
"id": tm.Id, | ||
}) | ||
|
||
u, err := pmeta.LoadApplicationURL(ctx, meta, AppPath, tm.Id) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := rd.Set("url", u); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return diag.FromErr(encodeTerraform(tm, rd)) | ||
} | ||
} | ||
|
||
func newResourceRead() schema.ReadContextFunc { | ||
return func(ctx context.Context, rd *schema.ResourceData, meta any) diag.Diagnostics { | ||
client, err := pmeta.LoadClient(ctx, meta) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
tm, err := client.GetTeam(ctx, rd.Id()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
tflog.Debug(ctx, "Succesfully fetched team data") | ||
|
||
u, err := pmeta.LoadApplicationURL(ctx, meta, AppPath, tm.Id) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := rd.Set("url", u); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return diag.FromErr(encodeTerraform(tm, rd)) | ||
} | ||
} | ||
|
||
func newResourceUpdate() schema.UpdateContextFunc { | ||
return func(ctx context.Context, rd *schema.ResourceData, meta any) diag.Diagnostics { | ||
payload, err := decodeTerraform(rd) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
client, err := pmeta.LoadClient(ctx, meta) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
tm, err := client.UpdateTeam(ctx, rd.Id(), &team.CreateUpdateTeamRequest{ | ||
Name: payload.Name, | ||
Description: payload.Description, | ||
Members: payload.Members, | ||
NotificationLists: payload.NotificationLists, | ||
}) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
u, err := pmeta.LoadApplicationURL(ctx, meta, AppPath, tm.Id) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := rd.Set("url", u); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
tflog.Debug(ctx, "Successfully updated team data") | ||
|
||
return diag.FromErr(encodeTerraform(tm, rd)) | ||
} | ||
} | ||
|
||
func newResourceDelete() schema.DeleteContextFunc { | ||
return func(ctx context.Context, rd *schema.ResourceData, meta any) diag.Diagnostics { | ||
client, err := pmeta.LoadClient(ctx, meta) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
tflog.Debug(ctx, "Deteting team resource", map[string]any{ | ||
"team-id": rd.Id(), | ||
}) | ||
|
||
return diag.FromErr(client.DeleteTeam(ctx, rd.Id())) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annoyingly required to have
http.NewServerMux
work as intended