Skip to content

Commit

Permalink
Merge pull request #1089 from jfrog/migrate-custom-webhooks-to-plugin…
Browse files Browse the repository at this point in the history
…-framework

Migrate custom webhooks to Plugin Framework
  • Loading branch information
alexhung authored Oct 4, 2024
2 parents b0a48e9 + 4ae9965 commit 620add7
Show file tree
Hide file tree
Showing 31 changed files with 3,484 additions and 2,119 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## 12.1.1 (October 1, 2024). Tested on Artifactory 7.90.13 with Terraform 1.9.6 and OpenTofu 1.8.2
## 12.1.1 (October 2, 2024). Tested on Artifactory 7.90.13 with Terraform 1.9.6 and OpenTofu 1.8.2

IMPROVEMENTS:

* resource/artifactory_\*\_webhook is migrated to Plugin Framework. PR: [#1087](https://github.com/jfrog/terraform-provider-artifactory/pull/1087)
* resource/artifactory_\*\_custom_webhook is migrated to Plugin Framework. PR: [#1089](https://github.com/jfrog/terraform-provider-artifactory/pull/1089)

## 12.1.0 (September 26, 2024). Tested on Artifactory 7.90.10 with Terraform 1.9.6 and OpenTofu 1.8.2

Expand Down
12 changes: 12 additions & 0 deletions pkg/artifactory/provider/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,29 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R
replication.NewLocalRepositoryMultiReplicationResource,
replication.NewRemoteRepositoryReplicationResource,
webhook.NewArtifactWebhookResource,
webhook.NewArtifactCustomWebhookResource,
webhook.NewArtifactLifecycleWebhookResource,
webhook.NewArtifactLifecycleCustomWebhookResource,
webhook.NewArtifactPropertyWebhookResource,
webhook.NewArtifactPropertyCustomWebhookResource,
webhook.NewArtifactoryReleaseBundleWebhookResource,
webhook.NewArtifactoryReleaseBundleCustomWebhookResource,
webhook.NewBuildWebhookResource,
webhook.NewBuildCustomWebhookResource,
webhook.NewDestinationWebhookResource,
webhook.NewDestinationCustomWebhookResource,
webhook.NewDistributionWebhookResource,
webhook.NewDistributionCustomWebhookResource,
webhook.NewDockerWebhookResource,
webhook.NewDockerCustomWebhookResource,
webhook.NewReleaseBundleWebhookResource,
webhook.NewReleaseBundleCustomWebhookResource,
webhook.NewReleaseBundleV2WebhookResource,
webhook.NewReleaseBundleV2CustomWebhookResource,
webhook.NewReleaseBundleV2PromotionWebhookResource,
webhook.NewReleaseBundleV2PromotionCustomWebhookResource,
webhook.NewUserWebhookResource,
webhook.NewUserCustomWebhookResource,
}
}

Expand Down
6 changes: 0 additions & 6 deletions pkg/artifactory/provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/remote"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/virtual"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/security"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/webhook"
utilsdk "github.com/jfrog/terraform-provider-shared/util/sdk"
)

Expand Down Expand Up @@ -124,10 +123,5 @@ func resourcesMap() map[string]*schema.Resource {
resourcesMap[federatedResourceName] = federated.ResourceArtifactoryFederatedGenericRepository(repoType)
}

for _, webhookType := range webhook.DomainSupported {
webhookCustomResourceName := fmt.Sprintf("artifactory_%s_custom_webhook", webhookType)
resourcesMap[webhookCustomResourceName] = webhook.ResourceArtifactoryCustomWebhook(webhookType)
}

return utilsdk.AddTelemetry(productId, resourcesMap)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"fmt"
"net/http"
"regexp"

"github.com/go-resty/resty/v2"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -161,6 +163,12 @@ func (r *ReleaseBundleV2PromotionResource) Configure(ctx context.Context, req re
r.ProviderData = req.ProviderData.(util.ProviderMetadata)
}

var retryOnNotAssignedToEnvironmentError = func(response *resty.Response, _r error) bool {
var notAssignedToEnvironmentRegex = regexp.MustCompile(".*not assigned to environment.*")

return notAssignedToEnvironmentRegex.MatchString(string(response.Body()[:]))
}

func (r *ReleaseBundleV2PromotionResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
go util.SendUsageResourceCreate(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

Expand Down Expand Up @@ -195,6 +203,7 @@ func (r *ReleaseBundleV2PromotionResource) Create(ctx context.Context, req resou
}).
SetBody(promotion).
SetResult(&result).
AddRetryCondition(retryOnNotAssignedToEnvironmentError).
Post(ReleaseBundleV2PromotionEndpoint)
if err != nil {
utilfw.UnableToCreateResourceError(resp, err.Error())
Expand Down
Loading

0 comments on commit 620add7

Please sign in to comment.