Skip to content

Commit

Permalink
Merge pull request #130 from jfrog/migrate-project-environment
Browse files Browse the repository at this point in the history
Migrate project_environment resource to Framework plugin
  • Loading branch information
alexhung authored May 31, 2024
2 parents 2e92895 + 772ca27 commit 80dfad9
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 218 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ BUG FIXES:

* Add validation to `roles` attribute for `project_group` and `project_user` resources to ensure at least one role is defined. Issue: [#126](https://github.com/jfrog/terraform-provider-project/issues/126) PR: [#129](https://github.com/jfrog/terraform-provider-project/pull/129)

IMPROVEMENTS:

* resource/project_environment is migrated to Plugin Framework. PR: [#130](https://github.com/jfrog/terraform-provider-project/pull/130)

## 1.6.0 (May 22, 2024)

FEATURES:
Expand Down
8 changes: 5 additions & 3 deletions pkg/project/acctest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ var testAccProviderConfigure sync.Once
// during acceptance tests. Use it only if you need to combine resources from SDK v2 and the Framework in the same test.
var ProtoV6MuxProviderFactories map[string]func() (tfprotov6.ProviderServer, error)

var ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"project": providerserver.NewProtocol6WithError(provider.Framework()()),
}
var ProtoV6ProviderFactories map[string]func() (tfprotov6.ProviderServer, error)

func init() {
Provider = provider.SdkV2()
Expand All @@ -50,6 +48,10 @@ func init() {
"project": func() (*schema.Provider, error) { return Provider, nil },
}

ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"project": providerserver.NewProtocol6WithError(provider.Framework()()),
}

ProtoV6MuxProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"project": func() (tfprotov6.ProviderServer, error) {
ctx := context.Background()
Expand Down
3 changes: 2 additions & 1 deletion pkg/project/provider/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ProjectProviderModel struct {

// Metadata satisfies the provider.Provider interface for ProjectProvider
func (p *ProjectProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "artifactory"
resp.TypeName = "project"
resp.Version = Version
}

Expand Down Expand Up @@ -181,6 +181,7 @@ func (p *ProjectProvider) Configure(ctx context.Context, req provider.ConfigureR
func (p *ProjectProvider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
project.NewProjectResource,
project.NewProjectEnvironmentResource,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/project/provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package provider

var Version = "0.0.1"
var Version = "1.6.1"

// needs to be exported so make file can update this
var productId = "terraform-provider-project/" + Version
9 changes: 4 additions & 5 deletions pkg/project/provider/sdkv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ func SdkV2() *schema.Provider {
ResourcesMap: sdk.AddTelemetry(
productId,
map[string]*schema.Resource{
"project_environment": resource.ProjectEnvironmentResource(),
"project_role": resource.ProjectRoleResource(),
"project_user": resource.ProjectUserResource(),
"project_group": resource.ProjectGroupResource(),
"project_repository": resource.ProjectRepositoryResource(),
"project_role": resource.ProjectRoleResource(),
"project_user": resource.ProjectUserResource(),
"project_group": resource.ProjectGroupResource(),
"project_repository": resource.ProjectRepositoryResource(),
},
),
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/project/resource/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/jfrog/terraform-provider-shared/util"
utilfw "github.com/jfrog/terraform-provider-shared/util/fw"
validatorfw_string "github.com/jfrog/terraform-provider-shared/validator/fw/string"
Expand Down Expand Up @@ -401,7 +400,7 @@ type ProjectAPIModel struct {
}

func (r *ProjectResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = "project"
resp.TypeName = req.ProviderTypeName
r.TypeName = resp.TypeName
}

Expand Down Expand Up @@ -692,10 +691,6 @@ func (r *ProjectResource) Schema(ctx context.Context, req resource.SchemaRequest
}),
Blocks: schemaV3.Blocks,
}

tflog.Debug(ctx, "Schema", map[string]any{
"schemaV4": resp.Schema,
})
}

func (r *ProjectResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
Expand Down
Loading

0 comments on commit 80dfad9

Please sign in to comment.