Skip to content

Commit

Permalink
feat: added import for slack and ms365
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Theuermann <[email protected]>
  • Loading branch information
mati007thm committed Jul 4, 2024
1 parent 15c840b commit 7199fd6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
16 changes: 8 additions & 8 deletions internal/provider/gql.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ type HostConfigurationOptions struct {
HTTP bool `graphql:"http"`
}

// type SlackConfigurationOptions struct {
// SlackToken string `graphql:"slackToken"`
// }
type SlackConfigurationOptions struct {
Placeholder string
}

type GithubConfigurationOptions struct {
Owner string
Expand Down Expand Up @@ -412,11 +412,11 @@ type GcpConfigurationOptions struct {

type ClientIntegrationConfigurationOptions struct {
// AWSConfigurationOptions AWSConfigurationOptions `graphql:"... on AWSConfigurationOptions"`
AzureConfigurationOptions AzureConfigurationOptions `graphql:"... on AzureConfigurationOptions"`
HostConfigurationOptions HostConfigurationOptions `graphql:"... on HostConfigurationOptions"`
Ms365ConfigurationOptions Ms365ConfigurationOptions `graphql:"... on Ms365ConfigurationOptions"`
GcpConfigurationOptions GcpConfigurationOptions `graphql:"... on GcpConfigurationOptions"`
// SlackConfigurationOptions SlackConfigurationOptions `graphql:"... on SlackConfigurationOptions"`
AzureConfigurationOptions AzureConfigurationOptions `graphql:"... on AzureConfigurationOptions"`
HostConfigurationOptions HostConfigurationOptions `graphql:"... on HostConfigurationOptions"`
Ms365ConfigurationOptions Ms365ConfigurationOptions `graphql:"... on Ms365ConfigurationOptions"`
GcpConfigurationOptions GcpConfigurationOptions `graphql:"... on GcpConfigurationOptions"`
SlackConfigurationOptions SlackConfigurationOptions `graphql:"... on SlackConfigurationOptions"`
GithubConfigurationOptions GithubConfigurationOptions `graphql:"... on GithubConfigurationOptions"`
HostedAwsConfigurationOptions HostedAwsConfigurationOptions `graphql:"... on HostedAwsConfigurationOptions"`
// Add other configuration options here
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/integration_github_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (r *integrationGithubResource) ImportState(ctx context.Context, req resourc
mrn := req.ID
integration, err := r.client.GetClientIntegration(ctx, mrn)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get Domain integration, got error: %s", err))
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get GitHub integration, got error: %s", err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions internal/provider/integration_ms365_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type integrationMs365ResourceModel struct {
TenantId types.String `tfsdk:"tenant_id"`

// credentials
Credential *integrationMs365CredentialModel `tfsdk:"credentials"`
Credential integrationMs365CredentialModel `tfsdk:"credentials"`
}

type integrationMs365CredentialModel struct {
Expand Down Expand Up @@ -233,7 +233,7 @@ func (r *integrationMs365Resource) ImportState(ctx context.Context, req resource
SpaceId: types.StringValue(strings.Split(integration.Mrn, "/")[len(strings.Split(integration.Mrn, "/"))-3]),
TenantId: types.StringValue(integration.ConfigurationOptions.Ms365ConfigurationOptions.TenantId),
ClientId: types.StringValue(integration.ConfigurationOptions.Ms365ConfigurationOptions.ClientId),
Credential: &integrationMs365CredentialModel{
Credential: integrationMs365CredentialModel{
PEMFile: types.StringPointerValue(nil),
},
}
Expand All @@ -243,5 +243,5 @@ func (r *integrationMs365Resource) ImportState(ctx context.Context, req resource
resp.State.SetAttribute(ctx, path.Root("name"), model.Name)
resp.State.SetAttribute(ctx, path.Root("tenant_id"), model.TenantId)
resp.State.SetAttribute(ctx, path.Root("client_id"), model.ClientId)
resp.State.SetAttribute(ctx, path.Root("pem_file"), model.Credential.PEMFile)
resp.State.SetAttribute(ctx, path.Root("credentials"), model.Credential)
}
18 changes: 16 additions & 2 deletions internal/provider/integration_slack_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package provider
import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand Down Expand Up @@ -197,5 +197,19 @@ func (r *integrationSlackResource) Delete(ctx context.Context, req resource.Dele
}

func (r *integrationSlackResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("mrn"), req, resp)
mrn := req.ID
integration, err := r.client.GetClientIntegration(ctx, mrn)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get Slack integration, got error: %s", err))
return
}

model := integrationSlackResourceModel{
Mrn: types.StringValue(string(integration.Mrn)),

Check failure on line 208 in internal/provider/integration_slack_resource.go

View workflow job for this annotation

GitHub Actions / Build

unnecessary conversion (unconvert)
Name: types.StringValue(string(integration.Name)),

Check failure on line 209 in internal/provider/integration_slack_resource.go

View workflow job for this annotation

GitHub Actions / Build

unnecessary conversion (unconvert)
SlackToken: types.StringPointerValue(nil),
SpaceId: types.StringValue(strings.Split(integration.Mrn, "/")[len(strings.Split(integration.Mrn, "/"))-3]),
}

resp.State.Set(ctx, &model)
}

0 comments on commit 7199fd6

Please sign in to comment.