Preformatted text
[quote=“qjqdave1, post:3, topic:7881”]
Terraform jfrog provider:
Create a replication between two artifactory local repositories
resource “artifactory_local_repository” “provider_test_source” {
key = “provider_test_source”
package_type = “maven”
}
resource “artifactory_local_repository” “provider_test_dest” {
key = “provider_test_dest”
package_type = “maven”
}
resource “” “foo-rep” {
repo_key = “ artifactorartifactorysinglereplicationconfigylocalrepository.providertestsource.key"cronexp=“00∗∗∗?“enableeventreplication=trueurl=”{artifactorartifactory_single_replication_configy_local_repository.provider_test_source.key}” cron_exp = “0 0 * * * ?” enable_event_replication = true url = " {var.artifactory_url}”
username = “ var.artifactoryusername"password="{var.artifactory_username}" password = " {var.artifactory_password}”
}
The key item is repo_key which works in this csse as it is a single instance and does not need a key surrounded by “” to dereference the
My example:
I would like to create multiple instances using for_each applied using replications_cofig data
replications_config -->
{
“replications_config”: {
“test-docker-repo”: {
“repo_key”: “artifactory_repository.docker-repos[test-docker-repo].key”,
“cron_exp”: “0 0 10 * * *”,
“enable_event_replication”: true,
“username”: “user”,
“password”: “passwd”,
},
“dev-docker-repo”: {
“repo_key”: “artifactory_repository.docker-repos[dev-docker-repo].key”,
“cron_exp”: “0 0 10 * * *”,
“enable_event_replication”: true,
“username”: “user”,
“password”: “passwd”,
},
…
}
}
resource “artifactory_single_replication_config” “pull-replications” {
for_each = var.replications_config
repo_key = each.value.repo_key
cron_exp = each.value.cron_exp
enable_event_replication = each.value.enable_event_replication
username = each.value.username
password = each.value.password
}
module.test_artifactory.artifactory_single_replication_config.pull-replications[“test-docker-repo”] will be created
- resource “artifactory_single_replication_config” “pull-replications” {
- cron_exp = “0 0 10 * * *”
- enable_event_replication = true
- enabled = (known after apply)
- id = (known after apply)
- password = (sensitive value)
- repo_key = “artifactory_repository.docker-repos[test-docker-repo].key” <--------------}
–
Error: PUT https://…/artifactory/api/replications/artifactory_repository.docker-repos[test-docker-repo].key: 400 [{Status:400 Message:Could not find repository}]
… in resource “artifactory_single_replication_config” “pull-replications”:
resource “artifactory_single_replication_config” “pull-replications”
Test 2
If trying to use format to create repo_key using " ->
“key_template”: “artifactory_repository.docker-repos%s%s%s].key”,
results in
- repo_key = “artifactory_repository.docker-repos[“test-docker-repo”].key”
and upon apply
PUT https://…/artifactory/api/replications/artifactory_repository.docker-repos%5B%22test-docker-repo%22%5D.key: 400 [{Status:400 Message:Could not find repository}]
due to url encoding.
Test 3
And if trying to format using “”" for formatting results in error
A comma is required to separate each
function argument from the next.Preformatted text
Is there a way to use for_each with the above resource.
Thanks
[/quote]
indent preformatted text by 4 spaces