Skip to content

Commit

Permalink
Merge pull request #2 from jfrog/add-custom-domain-name-resource
Browse files Browse the repository at this point in the history
Add resource 'myjfrog_custom_domain_name'
  • Loading branch information
alexhung authored Jul 19, 2024
2 parents 91b39cf + ae42ac9 commit e0eef99
Show file tree
Hide file tree
Showing 11 changed files with 918 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 1.0.0 (July 18, 2024)
## 1.0.0 (July 19, 2024). Tested on Artifactory with Terraform 1.9.2 and OpenTofu 1.7.3

FEATURES:

* **New Resource:** `myjfrog_ip_allowlist`: Resource to manage MyJFrog IP allowlist.
* **New Resource:** `myjfrog_custom_domain_name`: Resource to manage MyJFrog IP allowlist. PR: [#2](https://github.com/jfrog/terraform-provider-myjfrog/pull/2)
7 changes: 6 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ endif
PKG_NAME=pkg/${PRODUCT}
# if this path ever changes, you need to also update the 'ldflags' value in .goreleaser.yml
PKG_VERSION_PATH=github.com/jfrog/terraform-provider-${PRODUCT}/${PKG_NAME}
VERSION := $(shell git tag --sort=-creatordate | head -1 | sed -n 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1.\2.\3/p')
VERSION := $(shell git tag --sort=-creatordate | head -1 | sed -n 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1.\2.\3/p')

ifeq ($(VERSION),)
VERSION := "0.0.0"
endif

NEXT_VERSION?=$(shell echo ${VERSION}| awk -F '.' '{print $$1 "." $$2 "." $$3 +1 }')

TERRAFORM_CLI?=terraform
Expand Down
8 changes: 1 addition & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ terraform {
}
}
variable "jfrog_url" {
type = string
default = "http://localhost:8081"
}
provider "myfrog" {
// supply JFROG_MYJFROG_API_TOKEN as env var
}
Expand All @@ -52,14 +47,13 @@ MyJFrog API tokens may be used via the HTTP Authorization header by providing th
Usage:
```terraform
provider "myjfrog" {
url = "my.jfrog.io"
api_token = "abc...xy"
}
```

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

### Required
### Optional

- `api_token` (String, Sensitive) API token that allows you to make changes to your MyJFrog 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.
104 changes: 104 additions & 0 deletions docs/resources/custom_domain_name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "myjfrog_custom_domain_name Resource - terraform-provider-myjfrog"
subcategory: ""
description: |-
Provides a MyJFrog Custom Domain Name https://jfrog.com/help/r/jfrog-hosting-models-documentation/manage-custom-domain-names-in-myjfrog resource to manage custom domain names. Also see Custom Domain Name REST API https://jfrog.com/help/r/jfrog-rest-apis/custom-domain-name-rest-apis for more details.
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.
---

# myjfrog_custom_domain_name (Resource)

Provides a MyJFrog [Custom Domain Name](https://jfrog.com/help/r/jfrog-hosting-models-documentation/manage-custom-domain-names-in-myjfrog) resource to manage custom domain names. Also see [Custom Domain Name REST API](https://jfrog.com/help/r/jfrog-rest-apis/custom-domain-name-rest-apis) for more details.

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).

## Example Usage

```terraform
resource "myjfrog_custom_domain_name" "my-custom-domain-name" {
certificate_name = "mycert"
certificate_body = "-----BEGIN CERTIFICATE-----\nMIIETzCCAzegAwIBAgIGAY...jLjELMAkGA1UECwwC\n-----END CERTIFICATE-----\n"
certificate_chain = "-----BEGIN CERTIFICATE-----\nMIIETzCCAzegAwIBAgIGAY...jLjELMAkGA1UECwwC\n-----END CERTIFICATE-----\n"
certificate_private_key = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAqXr...rEgIP8TXkOkCaiA\n-----END RSA PRIVATE KEY-----\n"
domains_under_certificate = [
{
url = "servername1.com"
server_name = "serverName1"
type = "platform_base_url"
}
]
}
resource "myjfrog_custom_domain_name" "my-custom-domain-name-2" {
certificate_name = "mycert2"
certificate_body = <<EOT
-----BEGIN CERTIFICATE-----
MIIETzCCAzegAwIBAgIGAY...jLjELMAkGA1UECwwC
-----END CERTIFICATE-----
EOT
certificate_private_key = <<EOT
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAqXr...rEgIP8TXkOkCaiA\
-----END RSA PRIVATE KEY-----
EOT
domains_under_certificate = [
{
url = "servername1.com"
server_name = "serverName1"
type = "platform_base_url"
},
{
url = "servername2.com"
server_name = "serverName2"
type = "docker_sub_domain"
docker_repository_name_override = "docker-local"
}
]
}
```

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

### Required

- `certificate_body` (String) A certificate body is a text field containing information about the certificate such as the domain name, public key, signature algorithm, issuer, and validity period. You may include the certificate chain in the certificate body.
- `certificate_name` (String) Give your certificate a unique name to help identify it.
- `certificate_private_key` (String, Sensitive) The private key pairs with the certificate's public key for encryption. The keys must match. Private key must be in RSA format (RSA PKCS#1). If not, you can convert it to RSA using the following OpenSSL command:
`openssl rsa -in private.key -out private_rsa.key -traditional`
- `domains_under_certificate` (Attributes Set) (see [below for nested schema](#nestedatt--domains_under_certificate))

### Optional

- `certificate_chain` (String) A chain of trust between certificates that is anchored by a root certificate authority is used to verify the validity of a certificate.

### Read-Only

- `certificate_expiry` (Number)
- `certificate_status` (String)
- `id` (String) The ID of this resource.

<a id="nestedatt--domains_under_certificate"></a>
### Nested Schema for `domains_under_certificate`

Required:

- `server_name` (String) The server_name field in your request refers to the designated JFrog server where you intend to configure a CNAME (Canonical Name). For instance, if your JFrog server URL is myserver.jfrog.io, and you wish to set up a CNAME for this server, you should enter `myserver` in the server_name field.
- `type` (String) This attribute offers two valid options:
* `platform_base_url`: Use this option when configuring the base URL for accessing the JPD (JFrog Platform Distribution) User Interface. You can also employ this URL as the base for API calls.
* `docker_sub_domain`: Use this option when configuring the base URL for Docker-related operations, such as login, pull, and push actions, within the JPD. Please note that this parameter is exclusively available for JPD instances that have the Docker Subdomain method configured.
For more detailed information on the various Docker methods available in Artifactory, please refer to [Get Started With Artifactory as a Docker Registry](https://jfrog.com/help/r/jfrog-artifactory-documentation/get-started-with-artifactory-as-a-docker-registry).
- `url` (String)

Optional:

- `docker_repository_name_override` (String) Only available when `type` is set to `docker_sub_domain` (when configuring the base URL for Docker-related operations). Use this option when you wish to define an explicit repository name (not derived from the domain name) - please notice this is not best practice.

## Import

Import is supported using the following syntax:

```shell
terraform import myjfrog_custom_domain_name.my-custom-domain-name cert-id
```
1 change: 1 addition & 0 deletions examples/resources/myjfrog_custom_domain_name/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import myjfrog_custom_domain_name.my-custom-domain-name cert-id
40 changes: 40 additions & 0 deletions examples/resources/myjfrog_custom_domain_name/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "myjfrog_custom_domain_name" "my-custom-domain-name" {
certificate_name = "mycert"
certificate_body = "-----BEGIN CERTIFICATE-----\nMIIETzCCAzegAwIBAgIGAY...jLjELMAkGA1UECwwC\n-----END CERTIFICATE-----\n"
certificate_chain = "-----BEGIN CERTIFICATE-----\nMIIETzCCAzegAwIBAgIGAY...jLjELMAkGA1UECwwC\n-----END CERTIFICATE-----\n"
certificate_private_key = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAqXr...rEgIP8TXkOkCaiA\n-----END RSA PRIVATE KEY-----\n"
domains_under_certificate = [
{
url = "servername1.com"
server_name = "serverName1"
type = "platform_base_url"
}
]
}

resource "myjfrog_custom_domain_name" "my-custom-domain-name-2" {
certificate_name = "mycert2"
certificate_body = <<EOT
-----BEGIN CERTIFICATE-----
MIIETzCCAzegAwIBAgIGAY...jLjELMAkGA1UECwwC
-----END CERTIFICATE-----
EOT
certificate_private_key = <<EOT
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAqXr...rEgIP8TXkOkCaiA\
-----END RSA PRIVATE KEY-----
EOT
domains_under_certificate = [
{
url = "servername1.com"
server_name = "serverName1"
type = "platform_base_url"
},
{
url = "servername2.com"
server_name = "serverName2"
type = "docker_sub_domain"
docker_repository_name_override = "docker-local"
}
]
}
13 changes: 13 additions & 0 deletions pkg/myjfrog/myjfrog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package myjfrog

import "strings"

type MyJFrogResponseAPIModel struct {
Status string `json:"status"`
StatusCode int64 `json:"statusCode"`
Errors []string `json:"errors"`
}

func (m MyJFrogResponseAPIModel) Error() string {
return strings.Join(m.Errors, ", ")
}
6 changes: 4 additions & 2 deletions pkg/myjfrog/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func (p *MyJFrogProvider) Configure(ctx context.Context, req provider.ConfigureR
}

meta := util.ProviderMetadata{
Client: myJFrogClient,
Client: myJFrogClient,
ProductId: productId,
}

p.Meta = meta
Expand All @@ -96,14 +97,15 @@ func (p *MyJFrogProvider) DataSources(ctx context.Context) []func() datasource.D
func (p *MyJFrogProvider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
NewIPAllowListResource,
NewCustomDomainNameResource,
}
}

func (p *MyJFrogProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"api_token": schema.StringAttribute{
Required: true,
Optional: true,
Sensitive: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
Expand Down
Loading

0 comments on commit e0eef99

Please sign in to comment.