Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'ansible' package type #1036

Merged
merged 10 commits into from
Jul 26, 2024
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 11.3.0 (July 26, 2024). Tested on Artifactory 7.90.5 with Terraform 1.9.3 and OpenTofu 1.7.3

IMPROVEMENTS:

**New Data Source and Resource:**

* `artifactory_local_ansible_repository`
* `artifactory_remote_ansible_repository`
* `artifactory_virtual_ansible_repository`
* `artifactory_federated_ansible_repository`

`Ansible` package type is supported in Artfactory 7.90.1 and later.

## 11.2.2 (July 25, 2024). Tested on Artifactory 7.90.5 with Terraform 1.9.3 and OpenTofu 1.7.3

BUG FIXES:
Expand Down
31 changes: 31 additions & 0 deletions docs/data-sources/federated_ansible_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
subcategory: "Federated Repositories"
---
# Artifactory Federated Ansible Repository Data Source

Retrieves a federated Ansible repository.

## Example Usage

```hcl
data "artifactory_federated_ansible_repository" "federated-test-ansible-repo" {
key = "federated-test-ansible-repo"
}
```
## Argument Reference

* `key` - (Required) the identity key of the repo.

## Attribute Reference

The following attributes are supported, along with the [list of attributes from the local Ansible repository](local_ansible_repository.md):

* `member` - The list of Federated members and must contain this repository URL (configured base URL
`/artifactory/` + repo `key`). Note that each of the federated members will need to have a base URL set.
Please follow the [instruction](https://www.jfrog.com/confluence/display/JFROG/Working+with+Federated+Repositories#WorkingwithFederatedRepositories-SettingUpaFederatedRepository)
to set up Federated repositories correctly.
* `url` - Full URL to ending with the repository name.
* `enabled` - Represents the active state of the federated member. It is supported to change the enabled
status of my own member. The config will be updated on the other federated members automatically.
* `proxy` - Proxy key from Artifactory Proxies settings.
* `disable_proxy` - When set to `true`, the proxy is disabled, and not returned in the API response body. If there is a default proxy set for the Artifactory instance, it will be ignored, too.
27 changes: 27 additions & 0 deletions docs/data-sources/local_ansible_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
subcategory: "Local Repositories"
---

# Artifactory Local Ansible Repository Data Source

Retrieves a local Ansible repository.

## Example Usage

```hcl
data "artifactory_local_ansible_repository" "local-test-ansible-repo-basic" {
key = "local-test-ansible-repo-basic"
}
```

## Argument Reference

The following argument is supported:

* `key` - (Required) the identity key of the repo.

## Attribute Reference

The following attributes are supported, along with the [common list of attributes for the local repositories](local.md):

* `primary_keypair_ref` - The RSA key to be used to sign Ansible indices.
24 changes: 24 additions & 0 deletions docs/data-sources/remote_ansible_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
subcategory: "Remote Repositories"
---
# Artifactory Remote Ansible Repository Data Source

Retrieves a remote Ansible repository.

## Example Usage

```hcl
data "artifactory_remote_ansible_repository" "remote-ansible" {
key = "remote-ansible"
}
```

## Argument Reference

The following argument is supported:

* `key` - (Required) the identity key of the repo.

## Attribute Reference

The [common list of attributes for the remote repositories](../resources/remote.md) is supported.
27 changes: 27 additions & 0 deletions docs/data-sources/virtual_ansible_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
subcategory: "Virtual Repositories"
---
# Artifactory Virtual Ansible Repository Data Source

Retrieves a virtual Ansible repository.

## Example Usage

```hcl
data "artifactory_virtual_ansible_repository" "virtual-ansible" {
key = "virtual-ansible"
}
```

## Argument Reference

The following argument is supported:

* `key` - (Required) the identity key of the repo.

## Attribute Reference

The following attributes are supported, along with the [common list of attributes for the remote repositories](../resources/virtual.md):

* `primary_keypair_ref` - (Optional) Primary keypair used to sign artifacts. Default value is empty.
* `retrieval_cache_period_seconds` - (Optional, Default: `7200`) This value refers to the number of seconds to cache metadata files before checking for newer versions on aggregated repositories. A value of 0 indicates no caching.
47 changes: 47 additions & 0 deletions docs/resources/federated_ansible_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
subcategory: "Federated Repositories"
---
# Artifactory Federated Ansible Repository Resource

Creates a federated Ansible repository.

## Example Usage

```terraform
resource "artifactory_federated_ansible_repository" "terraform-federated-test-ansible-repo" {
key = "terraform-federated-test-ansible-repo"

member {
url = "http://tempurl.org/artifactory/terraform-federated-test-ansible-repo"
enabled = true
}

member {
url = "http://tempurl2.org/artifactory/terraform-federated-test-ansible-repo-2"
enabled = true
}
}
```

## Argument Reference

The following attributes are supported, along with the [list of attributes from the local Ansible repository](local_ansible_repository.md):

* `key` - (Required) the identity key of the repo.
* `member` - (Required) The list of Federated members and must contain this repository URL (configured base URL
`/artifactory/` + repo `key`). Note that each of the federated members will need to have a base URL set.
Please follow the [instruction](https://www.jfrog.com/confluence/display/JFROG/Working+with+Federated+Repositories#WorkingwithFederatedRepositories-SettingUpaFederatedRepository)
to set up Federated repositories correctly.
* `url` - (Required) Full URL to ending with the repository name.
* `enabled` - (Required) Represents the active state of the federated member. It is supported to change the enabled
status of my own member. The config will be updated on the other federated members automatically.
* `cleanup_on_delete` - (Optional) Delete all federated members on `terraform destroy` if set to `true`. Default is `false`. This attribute is added to match Terrform logic, so all the resources, created by the provider, must be removed on cleanup. Artifactory's behavior for the federated repositories is different, all the federated repositories stay after the user deletes the initial federated repository. **Caution**: if set to `true` all the repositories in the federation will be deleted, including repositories on other Artifactory instances in the "Circle of trust". This operation can not be reversed.
* `proxy` - (Optional) Proxy key from Artifactory Proxies settings. Default is empty field. Can't be set if `disable_proxy = true`.
* `disable_proxy` - (Optional, Default: `false`) When set to `true`, the proxy is disabled, and not returned in the API response body. If there is a default proxy set for the Artifactory instance, it will be ignored, too.

## Import

Federated repositories can be imported using their name, e.g.
```shell
terraform import artifactory_federated_ansible_repository.test-ansible-federated-repo test-ansible-federated-repo
```
49 changes: 49 additions & 0 deletions docs/resources/local_ansible_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
subcategory: "Local Repositories"
---
# Artifactory Local Ansible Repository Resource

Creates a local Ansible repository.

## Example Usage

```terraform
resource "artifactory_keypair" "some-keypair-RSA" {
pair_name = "some-keypair"
pair_type = "RSA"
alias = "foo-alias"
private_key = file("samples/rsa.priv")
public_key = file("samples/rsa.pub")
lifecycle {
ignore_changes = [
private_key,
passphrase,
]
}
}

resource "artifactory_local_ansible_repository" "test-ansible-local-repo" {
key = "test-ansible-local-repo"
primary_keypair_ref = artifactory_keypair.some-keypair-RSA.pair_name
}
```

## Argument Reference

Arguments have a one to one mapping with the [JFrog API](https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON).

The following arguments are supported, along with the [common list of arguments for the local repositories](local.md):

* `key` - (Required) the identity key of the repo.
* `primary_keypair_ref` - (Optional) The RSA key to be used to sign alpine indices.

Artifactory REST API call Get Key Pair doesn't return keys `private_key` and `passphrase`, but consumes these keys in the POST call.

The meta-argument `lifecycle` used here to make Provider ignore the changes for these two keys in the Terraform state.

## Import

Local repositories can be imported using their name, e.g.
```shell
terraform import artifactory_local_ansible_repository.test-ansible-local-repo test-ansible-local-repo
```
37 changes: 37 additions & 0 deletions docs/resources/remote_ansible_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
subcategory: "Remote Repositories"
---
# Artifactory Remote Ansible Repository Resource

Creates a remote Ansible repository.

Official documentation can be found [here](https://jfrog.com/help/r/jfrog-artifactory-documentation/ansible-repositories).


## Example Usage

```terraform
resource "artifactory_remote_alpine_repository" "my-remote-ansible" {
key = "my-remote-ansible"
url = "https://galaxy.ansible.com"
}
```

## Argument Reference

Arguments have a one to one mapping with the [JFrog API](https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON).

The following arguments are supported, along with the [common list of arguments for the remote repositories](remote.md):

* `key` - (Required) A mandatory identifier for the repository that must be unique. It cannot begin with a number or
contain spaces or special characters.
* `description` - (Optional)
* `notes` - (Optional)
* `url` - (Required) The remote repo URL.

## Import

Remote repositories can be imported using their name, e.g.
```shell
terraform import artifactory_remote_ansible_repository.my-remote-ansible my-remote-ansible
```
42 changes: 42 additions & 0 deletions docs/resources/virtual_ansible_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
subcategory: "Virtual Repositories"
---
# Artifactory Virtual Ansible Repository Resource

Creates a virtual Ansible repository.

Official documentation can be found [here](https://jfrog.com/help/r/jfrog-artifactory-documentation/create-virtual-ansible-repositories).

## Example Usage

```terraform
resource "artifactory_virtual_ansible_repository" "my-ansible-virtual" {
key = "my-ansible-virtual"
repositories = []
description = "A test virtual repo"
notes = "Internal description"
includes_pattern = "com/jfrog/**,cloud/jfrog/**"
excludes_pattern = "com/google/**"
}
```

## Argument Reference

Arguments have a one to one mapping with the [JFrog API](https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON).

The following arguments are supported, along with the [common list of arguments for the virtual repositories](virtual.md):

* `key` - (Required) A mandatory identifier for the repository that must be unique. It cannot begin with a number or
contain spaces or special characters.
* `repositories` - (Optional) The effective list of actual repositories included in this virtual repository.
* `description` - (Optional)
* `notes` - (Optional)
* `primary_keypair_ref` - (Optional) Primary keypair used to sign artifacts. Default value is empty.
* `retrieval_cache_period_seconds` - (Optional, Default: `7200`) This value refers to the number of seconds to cache metadata files before checking for newer versions on aggregated repositories. A value of 0 indicates no caching.

## Import

Virtual repositories can be imported using their name, e.g.
```shell
terraform import artifactory_virtual_ansible_repository.my-ansible-virtual my-ansible-virtual
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package federated

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/jfrog/terraform-provider-artifactory/v11/pkg/artifactory/datasource/repository"
resource_repository "github.com/jfrog/terraform-provider-artifactory/v11/pkg/artifactory/resource/repository"
"github.com/jfrog/terraform-provider-artifactory/v11/pkg/artifactory/resource/repository/federated"
"github.com/jfrog/terraform-provider-artifactory/v11/pkg/artifactory/resource/repository/local"
"github.com/jfrog/terraform-provider-shared/packer"
"github.com/jfrog/terraform-provider-shared/predicate"
utilsdk "github.com/jfrog/terraform-provider-shared/util/sdk"
)

func DataSourceArtifactoryFederatedAnsibleRepository() *schema.Resource {
packageType := "ansible"

ansibleFederatedSchema := utilsdk.MergeMaps(
local.AnsibleLocalSchema,
federatedSchema,
resource_repository.RepoLayoutRefSchema(rclass, packageType),
)

var packMembers = func(repo interface{}, d *schema.ResourceData) error {
members := repo.(*federated.AnsibleRepositoryParams).Members
return federated.PackMembers(members, d)
}

pkr := packer.Compose(
packer.Universal(
predicate.All(
predicate.NoClass,
predicate.Ignore("member", "terraform_type"),
),
),
packMembers,
)

constructor := func() (interface{}, error) {
return &federated.AnsibleRepositoryParams{
RepositoryBaseParams: local.RepositoryBaseParams{
PackageType: packageType,
Rclass: rclass,
},
}, nil
}

return &schema.Resource{
Schema: ansibleFederatedSchema,
ReadContext: repository.MkRepoReadDataSource(pkr, constructor),
Description: "Provides a data source for a federated Ansible repository",
}
}
Loading
Loading