Skip to content

Commit

Permalink
Merge pull request #112 from jfrog/add-azure-provider-type-to-oidc-co…
Browse files Browse the repository at this point in the history
…nfiguration

Add "Azure" provider type to OIDC configuration
  • Loading branch information
alexhung authored Jul 19, 2024
2 parents 968490c + 2f885b2 commit 4519e53
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.9.0 (July 19, 2024). Tested on Artifactory 7.84.17 with Terraform 1.9.2 and OpenTofu 1.7.3

IMPROVEMENTS:

* resource/platform_oidc_configuration: Add `Azure` option for `provider_type` attribute. PR: [#112](https://github.com/jfrog/terraform-provider-platform/pull/112)

## 1.8.2 (July 16, 2024). Tested on Artifactory 7.84.17 with Terraform 1.9.2 and OpenTofu 1.7.3

BUG FIXES:
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/oidc_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "platform_oidc_configuration" "my-generic-oidc-configuration" {

- `issuer_url` (String) OIDC issuer URL. For GitHub actions, the URL must be https://token.actions.githubusercontent.com.
- `name` (String) Name of the OIDC provider
- `provider_type` (String) Type of OIDC provider. Can be `generic` or `GitHub`.
- `provider_type` (String) Type of OIDC provider. Can be `generic`, `GitHub`, or `Azure`.

### Optional

Expand Down
1 change: 1 addition & 0 deletions pkg/platform/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
ProviderMetadata: util.ProviderMetadata{
Client: platformClient,
ArtifactoryVersion: artifactoryVersion,
ProductId: productId,
},
MyJFrogClient: myJFrogClient,
}
Expand Down
16 changes: 14 additions & 2 deletions pkg/platform/resource_global_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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/jfrog/terraform-provider-shared/util"
utilfw "github.com/jfrog/terraform-provider-shared/util/fw"
)

Expand Down Expand Up @@ -58,14 +59,17 @@ var _ resource.Resource = (*globalRoleResource)(nil)

type globalRoleResource struct {
ProviderData PlatformProviderMetadata
TypeName string
}

func NewGlobalRoleResource() resource.Resource {
return &globalRoleResource{}
return &globalRoleResource{
TypeName: "platform_global_role",
}
}

func (r *globalRoleResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_global_role"
resp.TypeName = r.TypeName
}

func (r *globalRoleResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand Down Expand Up @@ -195,6 +199,8 @@ func (r *globalRoleResource) Configure(ctx context.Context, req resource.Configu
}

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

var plan globalRoleResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -225,6 +231,8 @@ func (r *globalRoleResource) Create(ctx context.Context, req resource.CreateRequ
}

func (r *globalRoleResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
go util.SendUsageResourceRead(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var state globalRoleResourceModel

resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
Expand Down Expand Up @@ -267,6 +275,8 @@ func (r *globalRoleResource) Read(ctx context.Context, req resource.ReadRequest,
}

func (r *globalRoleResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
go util.SendUsageResourceUpdate(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var plan globalRoleResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -298,6 +308,8 @@ func (r *globalRoleResource) Update(ctx context.Context, req resource.UpdateRequ
}

func (r *globalRoleResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
go util.SendUsageResourceDelete(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var state globalRoleResourceModel

diags := req.State.Get(ctx, &state)
Expand Down
16 changes: 14 additions & 2 deletions pkg/platform/resource_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/jfrog/terraform-provider-shared/util"
utilfw "github.com/jfrog/terraform-provider-shared/util/fw"
"github.com/samber/lo"
)
Expand All @@ -24,14 +25,17 @@ var _ resource.Resource = (*licenseResource)(nil)

type licenseResource struct {
ProviderData PlatformProviderMetadata
TypeName string
}

func NewLicenseResource() resource.Resource {
return &licenseResource{}
return &licenseResource{
TypeName: "platform_license",
}
}

func (r *licenseResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_license"
resp.TypeName = r.TypeName
}

func (r *licenseResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand Down Expand Up @@ -108,6 +112,8 @@ func (r *licenseResource) Configure(ctx context.Context, req resource.ConfigureR
}

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

var plan licenseResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -165,6 +171,8 @@ func (r *licenseResource) Create(ctx context.Context, req resource.CreateRequest
}

func (r *licenseResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
go util.SendUsageResourceRead(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var state licenseResourceModel

resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
Expand Down Expand Up @@ -206,6 +214,8 @@ func (r *licenseResource) Read(ctx context.Context, req resource.ReadRequest, re
}

func (r *licenseResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
go util.SendUsageResourceUpdate(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var plan licenseResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -263,6 +273,8 @@ func (r *licenseResource) Update(ctx context.Context, req resource.UpdateRequest
}

func (r *licenseResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
go util.SendUsageResourceDelete(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

resp.Diagnostics.AddWarning(
"Unable to Delete Resource",
"License cannot be deleted.",
Expand Down
20 changes: 16 additions & 4 deletions pkg/platform/resource_oidc_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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/jfrog/terraform-provider-shared/util"
utilfw "github.com/jfrog/terraform-provider-shared/util/fw"
)

Expand All @@ -35,14 +36,17 @@ var _ resource.Resource = (*odicConfigurationResource)(nil)

type odicConfigurationResource struct {
ProviderData PlatformProviderMetadata
TypeName string
}

func NewOIDCConfigurationResource() resource.Resource {
return &odicConfigurationResource{}
return &odicConfigurationResource{
TypeName: "platform_oidc_configuration",
}
}

func (r *odicConfigurationResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_oidc_configuration"
resp.TypeName = r.TypeName
}

func (r *odicConfigurationResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand Down Expand Up @@ -73,9 +77,9 @@ func (r *odicConfigurationResource) Schema(ctx context.Context, req resource.Sch
"provider_type": schema.StringAttribute{
Required: true,
Validators: []validator.String{
stringvalidator.OneOf([]string{"generic", gitHubProviderType}...),
stringvalidator.OneOf([]string{"generic", gitHubProviderType, "Azure"}...),
},
MarkdownDescription: fmt.Sprintf("Type of OIDC provider. Can be `generic` or `%s`.", gitHubProviderType),
MarkdownDescription: fmt.Sprintf("Type of OIDC provider. Can be `generic`, `%s`, or `Azure`.", gitHubProviderType),
},
"audience": schema.StringAttribute{
Optional: true,
Expand Down Expand Up @@ -131,6 +135,8 @@ func (r *odicConfigurationResource) Configure(ctx context.Context, req resource.
}

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

var plan odicConfigurationResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -168,6 +174,8 @@ func (r *odicConfigurationResource) Create(ctx context.Context, req resource.Cre
}

func (r *odicConfigurationResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
go util.SendUsageResourceRead(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var state odicConfigurationResourceModel

resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
Expand Down Expand Up @@ -223,6 +231,8 @@ func (r *odicConfigurationResource) Read(ctx context.Context, req resource.ReadR
}

func (r *odicConfigurationResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
go util.SendUsageResourceUpdate(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var plan odicConfigurationResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -261,6 +271,8 @@ func (r *odicConfigurationResource) Update(ctx context.Context, req resource.Upd
}

func (r *odicConfigurationResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
go util.SendUsageResourceDelete(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var state odicConfigurationResourceModel

diags := req.State.Get(ctx, &state)
Expand Down
16 changes: 14 additions & 2 deletions pkg/platform/resource_oidc_identity_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/jfrog/terraform-provider-shared/util"
utilfw "github.com/jfrog/terraform-provider-shared/util/fw"
)

Expand All @@ -32,14 +33,17 @@ var _ resource.Resource = (*odicIdentityMappingResource)(nil)

type odicIdentityMappingResource struct {
ProviderData PlatformProviderMetadata
TypeName string
}

func NewOIDCIdentityMappingResource() resource.Resource {
return &odicIdentityMappingResource{}
return &odicIdentityMappingResource{
TypeName: "platform_oidc_identity_mapping",
}
}

func (r *odicIdentityMappingResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_oidc_identity_mapping"
resp.TypeName = r.TypeName
}

func (r *odicIdentityMappingResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand Down Expand Up @@ -252,6 +256,8 @@ func (r *odicIdentityMappingResource) Configure(ctx context.Context, req resourc
}

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

var plan odicIdentityMappingResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -283,6 +289,8 @@ func (r *odicIdentityMappingResource) Create(ctx context.Context, req resource.C
}

func (r *odicIdentityMappingResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
go util.SendUsageResourceRead(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var state odicIdentityMappingResourceModel

resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
Expand Down Expand Up @@ -328,6 +336,8 @@ func (r *odicIdentityMappingResource) Read(ctx context.Context, req resource.Rea
}

func (r *odicIdentityMappingResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
go util.SendUsageResourceUpdate(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var plan odicIdentityMappingResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -362,6 +372,8 @@ func (r *odicIdentityMappingResource) Update(ctx context.Context, req resource.U
}

func (r *odicIdentityMappingResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
go util.SendUsageResourceDelete(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var state odicIdentityMappingResourceModel

diags := req.State.Get(ctx, &state)
Expand Down
15 changes: 13 additions & 2 deletions pkg/platform/resource_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ var _ resource.Resource = (*permissionResource)(nil)

type permissionResource struct {
ProviderData PlatformProviderMetadata
TypeName string
}

func NewPermissionResource() resource.Resource {
return &permissionResource{}
return &permissionResource{
TypeName: "platform_permission",
}
}

func (r *permissionResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_permission"
resp.TypeName = r.TypeName
}

var usersGroupsAttributeSchema = func(description string) schema.SetNestedAttribute {
Expand Down Expand Up @@ -808,6 +811,8 @@ func (r *permissionResource) Configure(ctx context.Context, req resource.Configu
}

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

var plan permissionResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -838,6 +843,8 @@ func (r *permissionResource) Create(ctx context.Context, req resource.CreateRequ
}

func (r *permissionResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
go util.SendUsageResourceRead(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var state permissionResourceModel

resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
Expand Down Expand Up @@ -880,6 +887,8 @@ func (r *permissionResource) Read(ctx context.Context, req resource.ReadRequest,
}

func (r *permissionResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
go util.SendUsageResourceUpdate(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var plan permissionResourceModel

resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
Expand Down Expand Up @@ -918,6 +927,8 @@ func (r *permissionResource) Update(ctx context.Context, req resource.UpdateRequ
}

func (r *permissionResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
go util.SendUsageResourceDelete(ctx, r.ProviderData.Client.R(), r.ProviderData.ProductId, r.TypeName)

var data permissionResourceModel

diags := req.State.Get(ctx, &data)
Expand Down
Loading

0 comments on commit 4519e53

Please sign in to comment.