Skip to content

Commit

Permalink
Bump module major version to v2
Browse files Browse the repository at this point in the history
Remove deprecated provider attributes

Remove functional code from deprecated resource 'myjfrog_ip_allowlist'
  • Loading branch information
alexhung committed Dec 17, 2024
1 parent 84924f2 commit edeb6e7
Show file tree
Hide file tree
Showing 30 changed files with 152 additions and 725 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ builds:
flags:
- -trimpath
ldflags:
- '-s -w -X github.com/jfrog/terraform-provider-platform/pkg/platform.Version={{.Version}}'
- '-s -w -X github.com/jfrog/terraform-provider-platform/v{{.Major}}/pkg/platform.Version={{.Version}}'
goos:
- freebsd
- windows
Expand Down
2 changes: 0 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ provider "platform" {
### Optional

- `access_token` (String, Sensitive) This is a access token that can be given to you by your admin under `Platform Configuration -> User Management -> Access Tokens`. This can also be sourced from the `JFROG_ACCESS_TOKEN` environment variable.
- `check_license` (Boolean, Deprecated) Toggle for pre-flight checking of Artifactory Pro and Enterprise license. Default to `true`.
- `myjfrog_api_token` (String, Sensitive, Deprecated) MyJFrog API token that allows you to make changes to your JFrog account. See [Generate a Token in MyJFrog](https://jfrog.com/help/r/jfrog-hosting-models-documentation/generate-a-token-in-myjfrog) for more details. This can also be sourced from the `JFROG_MYJFROG_API_TOKEN` environment variable.
- `oidc_provider_name` (String) OIDC provider name. See [Configure an OIDC Integration](https://jfrog.com/help/r/jfrog-platform-administration-documentation/configure-an-oidc-integration) for more details.
- `tfc_credential_tag_name` (String) Terraform Cloud Workload Identity Token tag name. Use for generating multiple TFC workload identity tokens. When set, the provider will attempt to use env var with this tag name as suffix. **Note:** this is case sensitive, so if set to `JFROG`, then env var `TFC_WORKLOAD_IDENTITY_TOKEN_JFROG` is used instead of `TFC_WORKLOAD_IDENTITY_TOKEN`. See [Generating Multiple Tokens](https://developer.hashicorp.com/terraform/cloud-docs/workspaces/dynamic-provider-credentials/manual-generation#generating-multiple-tokens) on HCP Terraform for more details.
- `url` (String) JFrog Platform URL. This can also be sourced from the `JFROG_URL` environment variable.
2 changes: 1 addition & 1 deletion docs/resources/myjfrog_ip_allowlist.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "platform_myjfrog_ip_allowlist Resource - terraform-provider-platform"
subcategory: ""
subcategory: "Deprecated"
description: |-
Provides a MyJFrog IP allowlist https://jfrog.com/help/r/jfrog-hosting-models-documentation/configure-the-ip/cidr-allowlist resource to manage list of allow IP/CIDR addresses. To use this resource, you need an access token. Only a Primary Admin can generate MyJFrog tokens. For more information, see Generate a Token in MyJFrog https://jfrog.com/help/r/jfrog-hosting-models-documentation/generate-a-token-in-myjfrog.
->This resource is supported only on the Cloud (SaaS) platform.
Expand Down
1 change: 0 additions & 1 deletion docs/resources/saml_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ resource "platform_saml_settings" "my-okta-saml-settings" {
- `group_attribute` (String) The group attribute in the SAML login XML response. Note that the system will search for a case-sensitive match to an existing group..
- `ldap_group_settings` (Set of String) List of LDAP group setting names. Only support in Artifactory 7.98 or later. See [Enabling Synchronization of LDAP Groups for SAML SSO](https://jfrog.com/help/r/jfrog-platform-administration-documentation/enabling-synchronization-of-ldap-groups-for-saml-sso) for more details.
- `name_id_attribute` (String) The username attribute used to configure the SSO URL for the identity provider.
- `no_auto_user_creation` (Boolean, Deprecated) **Deprecated** Use `auto_user_creation` instead. When disabled, the system will automatically create new users for those who have logged in using SAML, and assign them to the default groups. Default value is `false`.
- `sync_groups` (Boolean) When set, in addition to the groups the user is already associated with, he will also be associated with the groups returned in the SAML login response. Note that the user's association with the returned groups is not persistent. It is only valid for the current login session. Default value is `false`.
- `use_encrypted_assertion` (Boolean) When set, an X.509 public certificate will be created by Artifactory. Download this certificate and upload it to your IDP and choose your own encryption algorithm. This process will let you encrypt the assertion section in your SAML response. Default value is `false`.
- `verify_audience_restriction` (Boolean) Set this flag to specify who the assertion is intended for. The "audience" will be the service provider and is typically a URL but can technically be formatted as any string of data. Default value is `true`.
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jfrog/terraform-provider-platform
module github.com/jfrog/terraform-provider-platform/v2

// if you need to do local dev, literally just uncomment the line below
// replace github.com/jfrog/terraform-provider-shared => ../terraform-provider-shared
Expand Down Expand Up @@ -73,7 +73,6 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/sethvargo/go-retry v0.3.0
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/jfrog/terraform-provider-platform/pkg/platform"
"github.com/jfrog/terraform-provider-platform/v2/pkg/platform"
)

// Run the docs generation tool, check its repository for more information on how it works and how docs
Expand Down
87 changes: 11 additions & 76 deletions pkg/platform/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

"github.com/go-resty/resty/v2"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/provider"
Expand All @@ -24,22 +23,15 @@ var productId = "terraform-provider-platform/" + Version

var _ provider.Provider = (*PlatformProvider)(nil)

type PlatformProviderMetadata struct {
util.ProviderMetadata
MyJFrogClient *resty.Client
}

type PlatformProvider struct {
Meta PlatformProviderMetadata
Meta util.ProviderMetadata
}

type platformProviderModel struct {
Url types.String `tfsdk:"url"`
AccessToken types.String `tfsdk:"access_token"`
MyJFrogAPIToken types.String `tfsdk:"myjfrog_api_token"`
OIDCProviderName types.String `tfsdk:"oidc_provider_name"`
TFCCredentialTagName types.String `tfsdk:"tfc_credential_tag_name"`
CheckLicense types.Bool `tfsdk:"check_license"`
}

func NewProvider() func() provider.Provider {
Expand Down Expand Up @@ -73,7 +65,7 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
return
}

platformClient, err := client.Build(url, productId)
restyClient, err := client.Build(url, productId)
if err != nil {
resp.Diagnostics.AddError(
"Error creating Resty client",
Expand All @@ -84,7 +76,7 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure

oidcProviderName := config.OIDCProviderName.ValueString()
if oidcProviderName != "" {
oidcAccessToken, err := util.OIDCTokenExchange(ctx, platformClient, oidcProviderName, config.TFCCredentialTagName.ValueString())
oidcAccessToken, err := util.OIDCTokenExchange(ctx, restyClient, oidcProviderName, config.TFCCredentialTagName.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Failed OIDC ID token exchange",
Expand All @@ -106,36 +98,16 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
accessToken = config.AccessToken.ValueString()
}

myJFrogAPIToken := util.CheckEnvVars([]string{"JFROG_MYJFROG_API_TOKEN"}, "")
if config.MyJFrogAPIToken.ValueString() != "" {
myJFrogAPIToken = config.MyJFrogAPIToken.ValueString()
}

if accessToken == "" && myJFrogAPIToken == "" {
resp.Diagnostics.AddError(
"Missing JFrog Access Token and MyJFrog API token",
"Neither Access Token nor MyJFrog API Token were found in environment variables or provider configuration. Provider will not function.",
)
return
}

if accessToken == "" {
resp.Diagnostics.AddWarning(
"Missing JFrog Access Token",
"Access Token was not found in the JFROG_ACCESS_TOKEN environment variable, provider configuration block access_token attribute, or Terraform Cloud TFC_WORKLOAD_IDENTITY_TOKEN environment variable. Platform functionality will be affected.",
)
}

if myJFrogAPIToken == "" {
resp.Diagnostics.AddWarning(
"Missing MyJFrog API Token",
"MyJFrog API Token was not found in the JFROG_MYJFROG_API_TOKEN environment variable or provider configuration block myjfrog_api_token attribute. MyJFrog functionality will be affected.",
)
}

artifactoryVersion := ""
if len(accessToken) > 0 {
_, err = client.AddAuth(platformClient, "", accessToken)
_, err = client.AddAuth(restyClient, "", accessToken)
if err != nil {
resp.Diagnostics.AddError(
"Error adding Auth to Resty client",
Expand All @@ -144,7 +116,7 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
return
}

version, err := util.GetArtifactoryVersion(platformClient)
version, err := util.GetArtifactoryVersion(restyClient)
if err != nil {
resp.Diagnostics.AddWarning(
"Error getting Artifactory version",
Expand All @@ -155,39 +127,16 @@ func (p *PlatformProvider) Configure(ctx context.Context, req provider.Configure
artifactoryVersion = version

featureUsage := fmt.Sprintf("Terraform/%s", req.TerraformVersion)
go util.SendUsage(ctx, platformClient.R(), productId, featureUsage)
}

myJFrogClient, err := client.Build("https://my.jfrog.com", productId)
if err != nil {
resp.Diagnostics.AddError(
"Error creating Resty client for MyJFrog",
err.Error(),
)
return
}

if len(myJFrogAPIToken) > 0 {
_, err := client.AddAuth(myJFrogClient, "", myJFrogAPIToken)
if err != nil {
resp.Diagnostics.AddError(
"Error adding Auth to Resty client for MyJFrog",
err.Error(),
)
return
}
go util.SendUsage(ctx, restyClient.R(), productId, featureUsage)
}

featureUsage := fmt.Sprintf("Terraform/%s", req.TerraformVersion)
go util.SendUsage(ctx, platformClient.R(), productId, featureUsage)
go util.SendUsage(ctx, restyClient.R(), productId, featureUsage)

meta := PlatformProviderMetadata{
ProviderMetadata: util.ProviderMetadata{
Client: platformClient,
ArtifactoryVersion: artifactoryVersion,
ProductId: productId,
},
MyJFrogClient: myJFrogClient,
meta := util.ProviderMetadata{
Client: restyClient,
ArtifactoryVersion: artifactoryVersion,
ProductId: productId,
}

p.Meta = meta
Expand Down Expand Up @@ -244,15 +193,6 @@ func (p *PlatformProvider) Schema(ctx context.Context, req provider.SchemaReques
},
MarkdownDescription: "This is a access token that can be given to you by your admin under `Platform Configuration -> User Management -> Access Tokens`. This can also be sourced from the `JFROG_ACCESS_TOKEN` environment variable.",
},
"myjfrog_api_token": schema.StringAttribute{
Optional: true,
Sensitive: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
MarkdownDescription: "MyJFrog API token that allows you to make changes to your JFrog account. See [Generate a Token in MyJFrog](https://jfrog.com/help/r/jfrog-hosting-models-documentation/generate-a-token-in-myjfrog) for more details. This can also be sourced from the `JFROG_MYJFROG_API_TOKEN` environment variable.",
DeprecationMessage: "MyJFrog API token is deprecated. Use provider 'jfrog/myjfrog' https://registry.terraform.io/providers/jfrog/myjfrog instead.",
},
"oidc_provider_name": schema.StringAttribute{
Optional: true,
Validators: []validator.String{
Expand All @@ -267,11 +207,6 @@ func (p *PlatformProvider) Schema(ctx context.Context, req provider.SchemaReques
},
Description: "Terraform Cloud Workload Identity Token tag name. Use for generating multiple TFC workload identity tokens. When set, the provider will attempt to use env var with this tag name as suffix. **Note:** this is case sensitive, so if set to `JFROG`, then env var `TFC_WORKLOAD_IDENTITY_TOKEN_JFROG` is used instead of `TFC_WORKLOAD_IDENTITY_TOKEN`. See [Generating Multiple Tokens](https://developer.hashicorp.com/terraform/cloud-docs/workspaces/dynamic-provider-credentials/manual-generation#generating-multiple-tokens) on HCP Terraform for more details.",
},
"check_license": schema.BoolAttribute{
Optional: true,
MarkdownDescription: "Toggle for pre-flight checking of Artifactory Pro and Enterprise license. Default to `true`.",
DeprecationMessage: "Remove this attribute from your provider configuration as it is no longer used and the attribute will be removed in the next major version of the provider.",
},
},
}
}
4 changes: 2 additions & 2 deletions pkg/platform/resource_aws_iam_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewAWSIAMRoleResource() resource.Resource {
}

type AWSIAMRoleResource struct {
ProviderData PlatformProviderMetadata
ProviderData util.ProviderMetadata
TypeName string
}

Expand Down Expand Up @@ -79,7 +79,7 @@ func (r *AWSIAMRoleResource) Configure(ctx context.Context, req resource.Configu
if req.ProviderData == nil {
return
}
r.ProviderData = req.ProviderData.(PlatformProviderMetadata)
r.ProviderData = req.ProviderData.(util.ProviderMetadata)

supported, err := util.CheckVersion(r.ProviderData.ArtifactoryVersion, "7.90.10")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/resource_aws_iam_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/jfrog/terraform-provider-platform/pkg/platform"
"github.com/jfrog/terraform-provider-platform/v2/pkg/platform"
"github.com/jfrog/terraform-provider-shared/testutil"
"github.com/jfrog/terraform-provider-shared/util"
)
Expand Down
9 changes: 0 additions & 9 deletions pkg/platform/resource_crowd_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,6 @@ func (r *CrowdSettingsResource) Schema(ctx context.Context, req resource.SchemaR
}
}

func (r *CrowdSettingsResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}
m := req.ProviderData.(PlatformProviderMetadata).ProviderMetadata
r.ProviderData = &m
}

func (r *CrowdSettingsResource) 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
4 changes: 2 additions & 2 deletions pkg/platform/resource_global_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var globalRoleActions []string = []string{
var _ resource.Resource = (*globalRoleResource)(nil)

type globalRoleResource struct {
ProviderData PlatformProviderMetadata
ProviderData util.ProviderMetadata
TypeName string
}

Expand Down Expand Up @@ -195,7 +195,7 @@ func (r *globalRoleResource) Configure(ctx context.Context, req resource.Configu
if req.ProviderData == nil {
return
}
r.ProviderData = req.ProviderData.(PlatformProviderMetadata)
r.ProviderData = req.ProviderData.(util.ProviderMetadata)
}

func (r *globalRoleResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down
9 changes: 0 additions & 9 deletions pkg/platform/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,6 @@ type groupMembersResponseAPIModel struct {
Members []string `json:"members"`
}

func (r *groupResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}
m := req.ProviderData.(PlatformProviderMetadata).ProviderMetadata
r.ProviderData = &m
}

func (r *groupResource) 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
4 changes: 2 additions & 2 deletions pkg/platform/resource_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
var _ resource.Resource = (*licenseResource)(nil)

type licenseResource struct {
ProviderData PlatformProviderMetadata
ProviderData util.ProviderMetadata
TypeName string
}

Expand Down Expand Up @@ -108,7 +108,7 @@ func (r *licenseResource) Configure(ctx context.Context, req resource.ConfigureR
if req.ProviderData == nil {
return
}
r.ProviderData = req.ProviderData.(PlatformProviderMetadata)
r.ProviderData = req.ProviderData.(util.ProviderMetadata)
}

func (r *licenseResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down
Loading

0 comments on commit edeb6e7

Please sign in to comment.