Skip to content
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

Migrate custom webhooks to Plugin Framework #1089

Merged
merged 12 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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