From 7199fd6a752c4290ea86259b5c732bf276ca67ef Mon Sep 17 00:00:00 2001 From: Matthias Theuermann Date: Thu, 4 Jul 2024 10:58:15 +0200 Subject: [PATCH] feat: added import for slack and ms365 Signed-off-by: Matthias Theuermann --- internal/provider/gql.go | 16 ++++++++-------- .../provider/integration_github_resource.go | 2 +- .../provider/integration_ms365_resource.go | 6 +++--- .../provider/integration_slack_resource.go | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/internal/provider/gql.go b/internal/provider/gql.go index a289485..2ab72b2 100644 --- a/internal/provider/gql.go +++ b/internal/provider/gql.go @@ -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 @@ -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 diff --git a/internal/provider/integration_github_resource.go b/internal/provider/integration_github_resource.go index 15c9c74..1118c3e 100644 --- a/internal/provider/integration_github_resource.go +++ b/internal/provider/integration_github_resource.go @@ -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 } diff --git a/internal/provider/integration_ms365_resource.go b/internal/provider/integration_ms365_resource.go index 0e20ba0..0a6643e 100644 --- a/internal/provider/integration_ms365_resource.go +++ b/internal/provider/integration_ms365_resource.go @@ -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 { @@ -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), }, } @@ -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) } diff --git a/internal/provider/integration_slack_resource.go b/internal/provider/integration_slack_resource.go index 889de79..cd637dd 100644 --- a/internal/provider/integration_slack_resource.go +++ b/internal/provider/integration_slack_resource.go @@ -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" @@ -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)), + Name: types.StringValue(string(integration.Name)), + SlackToken: types.StringPointerValue(nil), + SpaceId: types.StringValue(strings.Split(integration.Mrn, "/")[len(strings.Split(integration.Mrn, "/"))-3]), + } + + resp.State.Set(ctx, &model) }