Skip to content

Commit

Permalink
Merge branch 'master' into jfrogGH-621-bulk-import
Browse files Browse the repository at this point in the history
  • Loading branch information
chb0github authored Oct 9, 2023
2 parents 7fb6218 + c8c984d commit 5afd562
Show file tree
Hide file tree
Showing 24 changed files with 784 additions and 67 deletions.
56 changes: 37 additions & 19 deletions .jfrog-pipelines/TFproviderTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ resources:
pipelines:
- name: tf_provider_artifactory
steps:
- name: build_and_run_tf_provider
type: Bash
- name: build_and_run_tf_provider_matrix
type: Matrix
stepMode: Bash
configuration:
#nodePool: default
multiNode: true
priority: 1
timeoutSeconds: 3600 # 60 minutes
runtime:
Expand Down Expand Up @@ -47,6 +49,25 @@ pipelines:
SONAR_SCANNER_VERSION: 4.7.0.2747
SONAR_SCANNER_HOME: $HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
SONAR_SCANNER_OPTS: "-server"
stepletMultipliers:
environmentVariables:
- directory: ./pkg/artifactory/datasource
- directory: ./pkg/artifactory/datasource/repository/federated
- directory: ./pkg/artifactory/datasource/repository/local
- directory: ./pkg/artifactory/datasource/repository/remote
- directory: ./pkg/artifactory/datasource/repository/virtual
- directory: ./pkg/artifactory/datasource/security
- directory: ./pkg/artifactory/datasource/user
- directory: ./pkg/artifactory/provider
- directory: ./pkg/artifactory/resource/configuration
- directory: ./pkg/artifactory/resource/replication
- directory: ./pkg/artifactory/resource/repository/federated
- directory: ./pkg/artifactory/resource/repository/local
- directory: ./pkg/artifactory/resource/repository/remote
- directory: ./pkg/artifactory/resource/repository/virtual
- directory: ./pkg/artifactory/resource/security
- directory: ./pkg/artifactory/resource/user
- directory: ./pkg/artifactory/resource/webhook
execution:
onStart:
- echo "Sending status to GitHub."
Expand All @@ -72,11 +93,8 @@ pipelines:
- echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
- sudo apt update
- sudo apt install goreleaser
# TODO: enable after migration to repo21
#- echo "Install SonarQube"
#- curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
#- unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
onExecute:
- echo "Executing matrix step on ${steplet_id}"
- add_run_variables TFProviderRepo=$(echo ${res_GitHubTFProviderRepoJFrog_gitRepoRepositorySshUrl} | sed -e 's/git@/@/g' -e 's/:/\//g')
- cd ${res_GitHubTFProviderRepoJFrog_resourcePath} # we need to manually move into the resource path
- echo "Verify the code contents merged feature branch with master branch (detached mode)"
Expand Down Expand Up @@ -106,23 +124,27 @@ pipelines:
- export ARTIFACTORY_CONTAINER_NAME=artifactory
- >-
docker run -i --name ${ARTIFACTORY_CONTAINER_NAME} -t -d --rm -v "${res_GitHubTFProviderRepoJFrog_resourcePath}/scripts/artifactory.lic:/artifactory_extra_conf/artifactory.lic:ro" \
-p8081:8081 -p8082:8082 -p8080:8080 releases-docker.jfrog.io/jfrog/artifactory-pro:${ARTIFACTORY_VERSION}
-p 8082:8082 releases-docker.jfrog.io/jfrog/artifactory-pro:${ARTIFACTORY_VERSION}
- echo "Set localhost to a container IP address, since we run docker inside of docker"
- export LOCALHOST=$(docker inspect -f '{{`{{range.NetworkSettings.Networks}}{{.Gateway}}{{end}}`}}' ${ARTIFACTORY_CONTAINER_NAME})
- echo "Using ${LOCALHOST} as 'localhost' ip address"
- echo "Waiting for Artifactory to start (doesn't reflect the start of the UI!)"
- export ARTIFACTORY_URL="http://${LOCALHOST}:8082"
- >-
until curl -sf -u admin:password http://${LOCALHOST}:8081/artifactory/api/system/licenses/; do
until curl -sf -u admin:password ${ARTIFACTORY_URL}/artifactory/api/system/licenses/; do
printf '.'
sleep 4
done
- echo "Add variables needed to run Terraform Provider"
- export ARTIFACTORY_URL="http://${LOCALHOST}:8082"
- export ARTIFACTORY_USERNAME=admin
- export ARTIFACTORY_PASSWORD=password
- echo "Get cookie to generate Access token. We need a pause to let UI come up to get cookies"
- sleep 180
- sudo curl http://${LOCALHOST}:8082/router/api/v1/system/health
- >-
until curl -sf -u admin:password ${ARTIFACTORY_URL}/ui/login/; do
printf '.'
sleep 4
done
- sudo curl ${ARTIFACTORY_URL}/router/api/v1/system/health
- >-
export COOKIES=$(curl -c - "${ARTIFACTORY_URL}/ui/api/v1/ui/auth/login?_spring_security_remember_me=false" \
--header "accept: application/json, text/plain, */*" \
Expand All @@ -139,22 +161,18 @@ pipelines:
- add_run_variables ARTIFACTORY_ACCESS_TOKEN=${ACCESS_KEY}
- echo "Unset ARTIFACTORY_PASSWORD, acceptance test will use ARTIFACTORY_ACCESS_TOKEN instead"
- unset ARTIFACTORY_PASSWORD
- export TF_ACC=true
- make acceptance
# TODO: enable after migration to repo21
#- export SONAR_TOKEN=${int_terraform_artifactory_sonarqube_token}
#- make scan
- TF_ACC=true make acceptance TEST=${directory}
- make install
onSuccess:
- echo "Success"
- send_notification partnership_slack --text "${pipeline_name} step <${step_url}|${step_name}> is completed. Version ${PROVIDER_VERSION:-" wasn't set"}."
- send_notification partnership_slack --text "${pipeline_name} step <${step_url}|${step_name} - ${directory}> is completed. Version ${PROVIDER_VERSION:-" wasn't set"}."
onFailure:
- echo "Failure, sending status to GitHub and Slack."
- export STATE="failure"
- export DESCRIPTION="Pipeline has failed."
- git clone https://${int_partnership_github_token}@github.com/jfrog/terraform-provider-shared.git
- ./terraform-provider-shared/scripts/github-status.sh ${res_GitHubTFProviderRepoJFrog_gitProvider_token} ${res_GitHubTFProviderRepoJFrog_gitRepoFullName} ${res_GitHubTFProviderRepoJFrog_commitSha}
- send_notification partnership_slack --text "${pipeline_name} pipeline failed on <${step_url}|${step_name}> step"
- send_notification partnership_slack --text "${pipeline_name} pipeline failed on <${step_url}|${step_name} - ${directory}> step"
onComplete:
- echo "Complete"

Expand All @@ -167,7 +185,7 @@ pipelines:
- name: partnership_slack
- name: partnership_github
inputSteps:
- name: build_and_run_tf_provider
- name: build_and_run_tf_provider_matrix
inputResources:
- name: GitHubTFProviderRepoJFrog
execution:
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
## 9.4.0 (Oct 5, 2023). Tested on Artifactory 7.68.13 with Terraform CLI v1.6.0

FEATURES:

* resource/artifactory_mail_server: add a new resource for managing mail server configuration. PR: [#819](https://github.com/jfrog/terraform-provider-artifactory/pull/819) Issue: [#735](https://github.com/jfrog/terraform-provider-artifactory/issues/735)

## 9.3.1 (Oct 6, 2023). Tested on Artifactory 7.68.13 with Terraform CLI v1.6.0

BUG FIX:
* resource/artifactory_scoped_token: Remove default value for `expires_in` attribute which should fix state drift when upgrading from 7.11.2 or earlier. Issue: [#818](https://github.com/jfrog/terraform-provider-artifactory/issues/818) PR: [#820](https://github.com/jfrog/terraform-provider-artifactory/pull/820)

## 9.3.0 (Oct 3, 2023). Tested on Artifactory 7.68.13 with Terraform CLI v1.5.7

IMPROVEMENTS:

* resource/artifactory_distribution_public_key is migrated to Plugin Framework. PR: [#817](https://github.com/jfrog/terraform-provider-artifactory/pull/817)
* resource/artifactory_remote_\*\_repository: Fix incorrect default value for `store_artifacts_locally` attribute in documentation. PR: [#816](https://github.com/jfrog/terraform-provider-artifactory/pull/816)


## 9.2.1 (Sep 29, 2023). Tested on Artifactory 7.68.11 with Terraform CLI v1.5.7

IMPROVEMENTS:
Expand Down
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TEST?=./...
TEST?=./pkg/...
PRODUCT=artifactory
GO_ARCH=$(shell go env GOARCH)
TARGET_ARCH=$(shell go env GOOS)_${GO_ARCH}
Expand Down Expand Up @@ -52,11 +52,11 @@ attach:

smoke: fmt
export TF_ACC=true && \
go test -run '${SMOKE_TESTS}' -ldflags="-X '${PKG_VERSION_PATH}.Version=${NEXT_PROVIDER_VERSION}-test'" -v -p 1 -timeout 5m ./pkg/... -count=1
go test -run '${SMOKE_TESTS}' -ldflags="-X '${PKG_VERSION_PATH}.Version=${NEXT_PROVIDER_VERSION}-test'" -v -p 1 -timeout 5m $(TEST). -count=1

acceptance: fmt
export TF_ACC=true && \
go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}.Version=${NEXT_PROVIDER_VERSION}-test'" -v -p 1 -parallel 20 -timeout 1h ./pkg/...
go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}.Version=${NEXT_PROVIDER_VERSION}-test'" -v -p 1 -parallel 20 -timeout 1h $(TEST)

coverage:
go tool cover -html=coverage.txt
Expand Down
57 changes: 57 additions & 0 deletions docs/resources/mail_server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "artifactory_mail_server Resource - terraform-provider-artifactory"
subcategory: "Configuration"
---

# Artifactory Mail Server Resource

Provides an Artifactory Mail Server resource. This can be used to create and manage Artifactory mail server configuration.

## Example Usages

```terraform
resource "artifactory_mail_server" "mymailserver" {
enabled = true
artifactory_url = "http://tempurl.org"
from = "[email protected]"
host = "http://tempurl.org"
username = "test-user"
password = "test-password"
port = 25
subject_prefix = "[Test]"
use_ssl = true
use_tls = true
}
```

## Argument reference

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `enabled` (Boolean) When set, mail notifications are enabled.
- `host` (String) The mail server IP address / DNS.
- `port` (Number) The port number of the mail server.

### Optional

- `artifactory_url` (String) The Artifactory URL to to link to in all outgoing messages.
- `from` (String) The 'from' address header to use in all outgoing messages.
- `password` (String) The password for authentication with the mail server.
- `subject_prefix` (String) A prefix to use for the subject of all outgoing mails.
- `use_ssl` (Boolean) When set to 'true', uses a secure connection to the mail server.
- `use_tls` (Boolean) When set to 'true', uses Transport Layer Security when connecting to the mail server.
- `username` (String) The username for authentication with the mail server.

## Import

Import is supported using the following syntax:

```shell
terraform import artifactory_mail_server.my-mail-server mymailserver
```

~>The `password` attribute is not retrievable from Artifactory thus there will be state drift after importing this resource.
2 changes: 1 addition & 1 deletion docs/resources/scoped_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ resource "artifactory_scoped_token" "audience" {

- `audiences` (Set of String) A list of the other instances or services that should accept this token identified by their Service-IDs. Limited to total 255 characters. Default to '*@*' if not set. Service ID must begin with valid JFrog service type. Options: jfrt, jfxr, jfpip, jfds, jfmc, jfac, jfevt, jfmd, jfcon, or *. For instructions to retrieve the Artifactory Service ID see this [documentation](https://jfrog.com/help/r/jfrog-rest-apis/get-service-id)
- `description` (String) Free text token description. Useful for filtering and managing tokens. Limited to 1024 characters.
- `expires_in` (Number) The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/revoke-token-by-id) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/using-the-revocable-and-persistency-thresholds) for details.
- `expires_in` (Number) The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/create-token) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/using-the-revocable-and-persistency-thresholds) for details.
- `grant_type` (String) The grant type used to authenticate the request. In this case, the only value supported is `client_credentials` which is also the default value if this parameter is not specified.
- `include_reference_token` (Boolean) Also create a reference token which can be used like an API key.
- `refreshable` (Boolean) Is this token refreshable? Default is `false`.
Expand Down
1 change: 1 addition & 0 deletions examples/resources/artifactory_mail_server/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import artifactory_mail_server.my-mail-server mymailserver
12 changes: 12 additions & 0 deletions examples/resources/artifactory_mail_server/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "artifactory_mail_server" "mymailserver" {
enabled = true
artifactory_url = "http://tempurl.org"
from = "[email protected]"
host = "http://tempurl.org"
username = "test-user"
password = "test-password"
port = 25
subject_prefix = "[Test]"
use_ssl = true
use_tls = true
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-framework v1.3.5
github.com/hashicorp/terraform-plugin-framework-validators v0.10.0
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-go v0.18.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-mux v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0
github.com/hashicorp/terraform-plugin-testing v1.5.1
github.com/jfrog/terraform-provider-shared v1.19.0
github.com/jfrog/terraform-provider-shared v1.20.0
github.com/sethvargo/go-password v0.2.0
github.com/stretchr/testify v1.7.2
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/hashicorp/terraform-plugin-docs v0.16.0 h1:UmxFr3AScl6Wged84jndJIfFcc
github.com/hashicorp/terraform-plugin-docs v0.16.0/go.mod h1:M3ZrlKBJAbPMtNOPwHicGi1c+hZUh7/g0ifT/z7TVfA=
github.com/hashicorp/terraform-plugin-framework v1.3.5 h1:FJ6s3CVWVAxlhiF/jhy6hzs4AnPHiflsp9KgzTGl1wo=
github.com/hashicorp/terraform-plugin-framework v1.3.5/go.mod h1:2gGDpWiTI0irr9NSTLFAKlTi6KwGti3AoU19rFqU30o=
github.com/hashicorp/terraform-plugin-framework-validators v0.10.0 h1:4L0tmy/8esP6OcvocVymw52lY0HyQ5OxB7VNl7k4bS0=
github.com/hashicorp/terraform-plugin-framework-validators v0.10.0/go.mod h1:qdQJCdimB9JeX2YwOpItEu+IrfoJjWQ5PhLpAOMDQAE=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
github.com/hashicorp/terraform-plugin-go v0.18.0 h1:IwTkOS9cOW1ehLd/rG0y+u/TGLK9y6fGoBjXVUquzpE=
github.com/hashicorp/terraform-plugin-go v0.18.0/go.mod h1:l7VK+2u5Kf2y+A+742GX0ouLut3gttudmvMgN0PA74Y=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
Expand All @@ -116,8 +116,8 @@ github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jfrog/terraform-provider-shared v1.19.0 h1:4/CgvSTqhf00eHMo8q+xL2/N8Lng7T+Pw5GbNSUwxRs=
github.com/jfrog/terraform-provider-shared v1.19.0/go.mod h1:JvTKRAXMQyX6gQjESY+YK2lJLeW8uKTVHar5HDTnvp0=
github.com/jfrog/terraform-provider-shared v1.20.0 h1:T5AFbn4Su3tlNZTIXwb8Bi4vq/LZMFH312V2z8d3IsI=
github.com/jfrog/terraform-provider-shared v1.20.0/go.mod h1:KEYnVOggRuQT6qLR05ra0QfQa0SeYnkMnN0ZqIgQHqI=
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
4 changes: 2 additions & 2 deletions pkg/artifactory/provider/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (p *ArtifactoryProvider) Configure(ctx context.Context, req provider.Config
fmt.Sprintf("%v", err),
)
}
if config.CheckLicense.IsNull() || config.CheckLicense.ValueBool() == true {
if config.CheckLicense.IsNull() || config.CheckLicense.ValueBool() {
licenseErr := utilsdk.CheckArtifactoryLicense(restyBase, "Enterprise", "Commercial", "Edge")
if licenseErr != nil {
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -159,7 +159,6 @@ func (p *ArtifactoryProvider) Configure(ctx context.Context, req provider.Config
Client: restyBase,
ArtifactoryVersion: version,
}

}

// Resources satisfies the provider.Provider interface for ArtifactoryProvider.
Expand All @@ -176,6 +175,7 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R
configuration.NewLdapSettingResource,
configuration.NewLdapGroupSettingResource,
configuration.NewBackupResource,
configuration.NewMailServerResource,
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/artifactory/provider/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package provider

var Version = "9.0.0" // needs to be exported so make file can update this
var productId = "terraform-provider-artifactory/" + Version
3 changes: 0 additions & 3 deletions pkg/artifactory/provider/sdkv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import (
"github.com/jfrog/terraform-provider-shared/validator"
)

var Version = "7.0.0" // needs to be exported so make file can update this
var productId = "terraform-provider-artifactory/" + Version

// SdkV2 Artifactory provider that supports configuration via Access Token
// Supported resources are repos, users, groups, replications, and permissions
func SdkV2() *schema.Provider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
utilfw "github.com/jfrog/terraform-provider-shared/util/fw"
utilsdk "github.com/jfrog/terraform-provider-shared/util/sdk"
validatorfw "github.com/jfrog/terraform-provider-shared/validator/fw"
validatorfw_string "github.com/jfrog/terraform-provider-shared/validator/fw/string"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -136,7 +136,7 @@ func (r *BackupResource) Schema(ctx context.Context, req resource.SchemaRequest,
MarkdownDescription: "Cron expression to control the backup frequency.",
Required: true,
Validators: []validator.String{
validatorfw.IsCron(),
validatorfw_string.IsCron(),
},
},
"retention_period_hours": schema.Int64Attribute{
Expand Down
Loading

0 comments on commit 5afd562

Please sign in to comment.