Skip to content

Commit

Permalink
added resource for bitbucket datacenter integration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mplushnikov committed Jan 2, 2024
1 parent 4d3a072 commit a98f8c7
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 61 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/bitbucket_datacenter_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ data "spacelift_bitbucket_datacenter_integration" "bitbucket_datacenter_integrat
- `api_host` (String) Bitbucket Datacenter integration api host
- `id` (String) The ID of this resource.
- `user_facing_host` (String) Bitbucket Datacenter integration user facing host
- `username` (String) Username which will be used to authenticate requests for cloning repositories
- `webhook_secret` (String) Bitbucket Datacenter integration webhook secret
- `webhook_url` (String) Bitbucket Datacenter integration webhook URL
46 changes: 46 additions & 0 deletions docs/resources/bitbucket_datacenter_integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "spacelift_bitbucket_datacenter_integration Resource - terraform-provider-spacelift"
subcategory: ""
description: |-
spacelift_bitbucket_datacenter_integration represents details of a bitbucket datacenter integration
---

# spacelift_bitbucket_datacenter_integration (Resource)

`spacelift_bitbucket_datacenter_integration` represents details of a bitbucket datacenter integration

## Example Usage

```terraform
resource "spacelift_bitbucket_datacenter_integration" "example" {
api_host = "private://bitbucket_spacelift/bitbucket"
user_facing_host = "https://bitbucket.spacelift.io/bitbucket"
username = "bitbucket_user_name"
access_token = "ABCD-MDQ3NzgxMzg3NzZ0VpOejJZmQfBBlpxxJuK9j1LLQG8g"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `access_token` (String, Sensitive) User access token from Bitbucket
- `api_host` (String) The API host where requests will be sent
- `user_facing_host` (String) User Facing Host which will be user for all user-facing URLs displayed in the Spacelift UI
- `username` (String) Username which will be used to authenticate requests for cloning repositories

### Read-Only

- `id` (String) The ID of this resource.
- `webhook_secret` (String, Sensitive) Secret for webhooks originating from Bitbucket repositories
- `webhook_url` (String) URL for webhooks originating from Bitbucket repositories

## Import

Import is supported using the following syntax:

```shell
terraform import spacelift_bitbucket_datacenter_integration.example spacelift_bitbucket_datacenter_integration_id
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import spacelift_bitbucket_datacenter_integration.example spacelift_bitbucket_datacenter_integration_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "spacelift_bitbucket_datacenter_integration" "example" {
api_host = "private://bitbucket_spacelift/bitbucket"
user_facing_host = "https://bitbucket.spacelift.io/bitbucket"
username = "bitbucket_user_name"
access_token = "ABCD-MDQ3NzgxMzg3NzZ0VpOejJZmQfBBlpxxJuK9j1LLQG8g"
}
42 changes: 16 additions & 26 deletions spacelift/data_bitbucket_datacenter_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,37 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

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

var bitbucketDatacenterFields = struct {
UserFacingHost string
APIHost string
WebhookSecret string
WebhookURL string
}{
UserFacingHost: "user_facing_host",
APIHost: "api_host",
WebhookSecret: "webhook_secret",
WebhookURL: "webhook_url",
}

func dataBitbucketDatacenterIntegration() *schema.Resource {
return &schema.Resource{
Description: "`spacelift_bitbucket_datacenter_integration` returns details about Bitbucket Datacenter integration",

ReadContext: dataBitbucketDatacenterIntegrationRead,

Schema: map[string]*schema.Schema{
bitbucketDatacenterFields.APIHost: {
structs.BitbucketDatacenterFields.APIHost: {
Type: schema.TypeString,
Description: "Bitbucket Datacenter integration api host",
Computed: true,
},
bitbucketDatacenterFields.WebhookSecret: {
structs.BitbucketDatacenterFields.Username: {
Type: schema.TypeString,
Description: "Username which will be used to authenticate requests for cloning repositories",
Computed: true,
},
structs.BitbucketDatacenterFields.WebhookSecret: {
Type: schema.TypeString,
Description: "Bitbucket Datacenter integration webhook secret",
Computed: true,
},
bitbucketDatacenterFields.WebhookURL: {
structs.BitbucketDatacenterFields.WebhookURL: {
Type: schema.TypeString,
Description: "Bitbucket Datacenter integration webhook URL",
Computed: true,
},
bitbucketDatacenterFields.UserFacingHost: {
structs.BitbucketDatacenterFields.UserFacingHost: {
Type: schema.TypeString,
Description: "Bitbucket Datacenter integration user facing host",
Computed: true,
Expand All @@ -54,12 +48,7 @@ func dataBitbucketDatacenterIntegration() *schema.Resource {

func dataBitbucketDatacenterIntegrationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var query struct {
BitbucketDataCenterIntegration *struct {
APIHost string `graphql:"apiHost"`
WebhookSecret string `graphql:"webhookSecret"`
UserFacingHost string `graphql:"userFacingHost"`
WebhookURL string `graphql:"webhookURL"`
} `graphql:"bitbucketDatacenterIntegration"`
BitbucketDataCenterIntegration *structs.BitbucketDatacenterIntegration `graphql:"bitbucketDatacenterIntegration"`
}

if err := meta.(*internal.Client).Query(ctx, "BitbucketDatacenterIntegrationRead", &query, map[string]interface{}{}); err != nil {
Expand All @@ -72,10 +61,11 @@ func dataBitbucketDatacenterIntegrationRead(ctx context.Context, d *schema.Resou
}

d.SetId("spacelift_bitbucket_datacenter_integration_id") // TF expects id to be set otherwise it will fail
d.Set(bitbucketDatacenterFields.APIHost, bitbucketDatacenterIntegration.APIHost)
d.Set(bitbucketDatacenterFields.WebhookSecret, bitbucketDatacenterIntegration.WebhookSecret)
d.Set(bitbucketDatacenterFields.WebhookURL, bitbucketDatacenterIntegration.WebhookURL)
d.Set(bitbucketDatacenterFields.UserFacingHost, bitbucketDatacenterIntegration.UserFacingHost)
d.Set(structs.BitbucketDatacenterFields.APIHost, bitbucketDatacenterIntegration.APIHost)
d.Set(structs.BitbucketDatacenterFields.WebhookSecret, bitbucketDatacenterIntegration.WebhookSecret)
d.Set(structs.BitbucketDatacenterFields.WebhookURL, bitbucketDatacenterIntegration.WebhookURL)
d.Set(structs.BitbucketDatacenterFields.UserFacingHost, bitbucketDatacenterIntegration.UserFacingHost)
d.Set(structs.BitbucketDatacenterFields.Username, bitbucketDatacenterIntegration.Username)

return nil
}
28 changes: 28 additions & 0 deletions spacelift/internal/structs/bitbucket_datacenter_integration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package structs

// BitbucketDatacenterIntegration represents the bitbucket datacenter integration data relevant to the provider.
type BitbucketDatacenterIntegration struct {
Id string `graphql:"id"`
Name string `graphql:"name"`
APIHost string `graphql:"apiHost"`
Username string `graphql:"username"`
UserFacingHost string `graphql:"userFacingHost"`
WebhookSecret string `graphql:"webhookSecret"`
WebhookURL string `graphql:"webhookURL"`
}

var BitbucketDatacenterFields = struct {
UserFacingHost string
Username string
AccessToken string
APIHost string
WebhookSecret string
WebhookURL string
}{
UserFacingHost: "user_facing_host",
Username: "username",
AccessToken: "access_token",
APIHost: "api_host",
WebhookSecret: "webhook_secret",
WebhookURL: "webhook_url",
}
71 changes: 36 additions & 35 deletions spacelift/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,41 +98,42 @@ func Provider(commit, version string) plugin.ProviderFunc {
"spacelift_worker_pools": dataWorkerPools(),
},
ResourcesMap: map[string]*schema.Resource{
"spacelift_aws_role": resourceAWSRole(),
"spacelift_aws_integration": resourceAWSIntegration(),
"spacelift_aws_integration_attachment": resourceAWSIntegrationAttachment(),
"spacelift_azure_integration": resourceAzureIntegration(),
"spacelift_azure_integration_attachment": resourceAzureIntegrationAttachment(),
"spacelift_blueprint": resourceBlueprint(),
"spacelift_context_attachment": resourceContextAttachment(),
"spacelift_context": resourceContext(),
"spacelift_drift_detection": resourceDriftDetection(),
"spacelift_environment_variable": resourceEnvironmentVariable(),
"spacelift_gcp_service_account": resourceGCPServiceAccount(),
"spacelift_idp_group_mapping": resourceIdpGroupMapping(),
"spacelift_module": resourceModule(),
"spacelift_mounted_file": resourceMountedFile(),
"spacelift_policy_attachment": resourcePolicyAttachment(),
"spacelift_policy": resourcePolicy(),
"spacelift_run": resourceRun(),
"spacelift_space": resourceSpace(),
"spacelift_scheduled_task": resourceScheduledTask(),
"spacelift_scheduled_delete_stack": resourceScheduledDeleteStack(),
"spacelift_stack": resourceStack(),
"spacelift_stack_dependency": resourceStackDependency(),
"spacelift_stack_dependency_reference": resourceStackDependencyReference(),
"spacelift_stack_activator": resourceStackActivator(),
"spacelift_stack_destructor": resourceStackDestructor(),
"spacelift_stack_aws_role": resourceStackAWSRole(), // deprecated
"spacelift_stack_gcp_service_account": resourceStackGCPServiceAccount(), // deprecated
"spacelift_terraform_provider": resourceTerraformProvider(),
"spacelift_user": resourceUser(),
"spacelift_vcs_agent_pool": resourceVCSAgentPool(),
"spacelift_webhook": resourceWebhook(),
"spacelift_named_webhook": resourceNamedWebhook(),
"spacelift_named_webhook_secret_header": resourceNamedWebhookSecretHeader(),
"spacelift_worker_pool": resourceWorkerPool(),
"spacelift_version": resourceVersion(),
"spacelift_aws_role": resourceAWSRole(),
"spacelift_aws_integration": resourceAWSIntegration(),
"spacelift_aws_integration_attachment": resourceAWSIntegrationAttachment(),
"spacelift_azure_integration": resourceAzureIntegration(),
"spacelift_azure_integration_attachment": resourceAzureIntegrationAttachment(),
"spacelift_blueprint": resourceBlueprint(),
"spacelift_bitbucket_datacenter_integration": resourceBitbucketDatacenterIntegration(),
"spacelift_context_attachment": resourceContextAttachment(),
"spacelift_context": resourceContext(),
"spacelift_drift_detection": resourceDriftDetection(),
"spacelift_environment_variable": resourceEnvironmentVariable(),
"spacelift_gcp_service_account": resourceGCPServiceAccount(),
"spacelift_idp_group_mapping": resourceIdpGroupMapping(),
"spacelift_module": resourceModule(),
"spacelift_mounted_file": resourceMountedFile(),
"spacelift_policy_attachment": resourcePolicyAttachment(),
"spacelift_policy": resourcePolicy(),
"spacelift_run": resourceRun(),
"spacelift_space": resourceSpace(),
"spacelift_scheduled_task": resourceScheduledTask(),
"spacelift_scheduled_delete_stack": resourceScheduledDeleteStack(),
"spacelift_stack": resourceStack(),
"spacelift_stack_dependency": resourceStackDependency(),
"spacelift_stack_dependency_reference": resourceStackDependencyReference(),
"spacelift_stack_activator": resourceStackActivator(),
"spacelift_stack_destructor": resourceStackDestructor(),
"spacelift_stack_aws_role": resourceStackAWSRole(), // deprecated
"spacelift_stack_gcp_service_account": resourceStackGCPServiceAccount(), // deprecated
"spacelift_terraform_provider": resourceTerraformProvider(),
"spacelift_user": resourceUser(),
"spacelift_vcs_agent_pool": resourceVCSAgentPool(),
"spacelift_webhook": resourceWebhook(),
"spacelift_named_webhook": resourceNamedWebhook(),
"spacelift_named_webhook_secret_header": resourceNamedWebhookSecretHeader(),
"spacelift_worker_pool": resourceWorkerPool(),
"spacelift_version": resourceVersion(),
},
ConfigureContextFunc: configureProvider(commit, version),
}
Expand Down
Loading

0 comments on commit a98f8c7

Please sign in to comment.