Skip to content

Commit

Permalink
Merge pull request jfrog#819 from jfrog/jfrogGH-735-add-resource-for-…
Browse files Browse the repository at this point in the history
…mail-server

Add resource for mail server
  • Loading branch information
alexhung authored Oct 6, 2023
2 parents b1cd6a9 + b75bcaf commit c8c984d
Show file tree
Hide file tree
Showing 20 changed files with 678 additions and 40 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 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:
Expand All @@ -10,7 +16,6 @@ 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
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.
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestAccBackup_importNotFound(t *testing.T) {
`
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5MuxProviderFactories,
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -134,12 +134,12 @@ func TestAccBackup_invalid_cron(t *testing.T) {
`
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5MuxProviderFactories,
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: config,
ResourceName: "artifactory_backup.invalid-cron-test",
ExpectError: regexp.MustCompile("value must match be a valid cron expression"),
ExpectError: regexp.MustCompile("value must be a valid cron expression"),
},
},
})
Expand Down Expand Up @@ -180,7 +180,7 @@ func cronTestCase(cronExpression string, t *testing.T) (*testing.T, resource.Tes

return t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5MuxProviderFactories,
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: acctest.VerifyDeleted(fqrn, acctest.CheckRepo),
Steps: []resource.TestStep{
{
Expand Down
Loading

0 comments on commit c8c984d

Please sign in to comment.