jfrog / terraform-provider-artifactory

Terraform provider to manage JFrog Artifactory
https://jfrog.com/artifactory
Apache License 2.0
272 stars 102 forks source link

JFrog Cloud Artifactory #25

Closed Nexus357ZA closed 3 years ago

Nexus357ZA commented 3 years ago

It does not seem like JFrog Cloud Artifactory is supported.

Configured the provider :

provider "artifactory" { url = "org_name.jfrog.io/artifactory" username = var.artifactory_username password = var.artifactory_password }

which produces the following error

Error: Get "/org_name.jfrog.io/artifactory/org_name.jfrog.io/artifactory/api/system/ping": unsupported protocol scheme ""

chb0github commented 3 years ago

I will have a look at it today.

chb0github commented 3 years ago

I run a simple TF locally and all is well. This is running against our saas platform. So, I am going to need the TF you're using, otherwise I am not seeing a problem

# Required for Terraform 0.13 and up (https://www.terraform.io/upgrade-guides/0-13.html)
terraform {
  required_providers {
    artifactory = {
      source  = "registry.terraform.io/jfrog/artifactory"
      version = "2.2.4"
    }
  }
}
provider "artifactory" {
  url = "https://partnership.jfrog.io/artifactory"
  api_key = "your api key here"
}

resource "artifactory_group" "test-group" {
  name             = "terraform1"
  description      = "test group"
  admin_privileges = false
}

//# Create a new Artifactory group called terraform
resource "artifactory_user" "test-user" {
  name     = "terraform"
  email    = "terraform@artifactory-terraform.com"
  groups   = [
    artifactory_group.test-group.name, # depend on group before creating user
    "readers",
  ]
  password = "Password1"
}

running it

christianb@christianb-mac terraform-provider-artifactory % tf init 

Initializing the backend...

Initializing provider plugins...
- Using previously-installed jfrog/artifactory v2.2.4

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
christianb@christianb-mac terraform-provider-artifactory % tf apply
random_string.random: Refreshing state... [id=wHiAZrvSTquDF/�i]
artifactory_group.test-group: Refreshing state... [id=terraform1]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # artifactory_group.test-group will be created
  + resource "artifactory_group" "test-group" {
      + admin_privileges = false
      + auto_join        = (known after apply)
      + description      = "test group"
      + id               = (known after apply)
      + name             = "terraform1"
      + realm            = (known after apply)
    }

  # artifactory_user.test-user will be created
  + resource "artifactory_user" "test-user" {
      + admin                      = (known after apply)
      + disable_ui_access          = (known after apply)
      + email                      = "terraform@artifactory-terraform.com"
      + groups                     = [
          + "readers",
          + "terraform1",
        ]
      + id                         = (known after apply)
      + internal_password_disabled = (known after apply)
      + name                       = "terraform"
      + password                   = (sensitive value)
      + profile_updatable          = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

artifactory_group.test-group: Creating...
artifactory_group.test-group: Creation complete after 0s [id=terraform1]
artifactory_user.test-user: Creating...
artifactory_user.test-user: Creation complete after 0s [id=terraform]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
christianb@christianb-mac terraform-provider-artifactory % 
Nexus357ZA commented 3 years ago
terraform {
  required_providers {
    artifactory = {
      source = "jfrog/artifactory"
      version = "2.2.4"
    }
  }
}

provider "artifactory" {
  url = "myorg.jfrog.io/artifactory"
  username = var.artifactory_username
  password = var.artifactory_password
}

resource "artifactory_local_repository" "docker-dev-local" {
  key = "docker-dev-local"
  package_type = "docker"
}

On terraform apply:

Error: Get "/lkwd.jfrog.io/artifactory/lkwd.jfrog.io/artifactory/api/system/ping": unsupported protocol scheme ""

  on main.tf line 17, in provider "artifactory":
  17: provider "artifactory" {

`

chb0github commented 3 years ago

Hey @Nexus357ZA

Looking at your error/tf I am definitely head scratching. Message received.

chb0github commented 3 years ago
terraform {
  required_providers {
    artifactory = {
      source  = "registry.terraform.io/jfrog/artifactory"
      version = "2.2.5"
    }
  }
}
provider "artifactory" {
  url = "https://partnership.jfrog.io/artifactory"
  api_key = "xxxxxx"
}
resource "artifactory_local_repository" "docker-dev-local" {
  key = "docker-dev-local"
  package_type = "docker"
}

results:

christianb@christianb-mac terraform-provider-artifactory % terraform init 

Initializing the backend...

Initializing provider plugins...
- Using previously-installed jfrog/artifactory v2.2.5

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
christianb@christianb-mac terraform-provider-artifactory % terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # artifactory_local_repository.docker-dev-local will be created
  + resource "artifactory_local_repository" "docker-dev-local" {
      + blacked_out                     = (known after apply)
      + checksum_policy_type            = (known after apply)
      + docker_api_version              = (known after apply)
      + enable_file_lists_indexing      = (known after apply)
      + excludes_pattern                = (known after apply)
      + force_nuget_authentication      = (known after apply)
      + handle_releases                 = (known after apply)
      + handle_snapshots                = (known after apply)
      + id                              = (known after apply)
      + includes_pattern                = (known after apply)
      + key                             = "docker-dev-local"
      + max_unique_snapshots            = (known after apply)
      + max_unique_tags                 = (known after apply)
      + package_type                    = "docker"
      + repo_layout_ref                 = (known after apply)
      + snapshot_version_behavior       = (known after apply)
      + suppress_pom_consistency_checks = (known after apply)
      + xray_index                      = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

artifactory_local_repository.docker-dev-local: Creating...
artifactory_local_repository.docker-dev-local: Creation complete after 1s [id=docker-dev-local]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
christianb@christianb-mac terraform-provider-artifactory % 

I would say the issue is with the state in your s3 bucket.

nc-andersenb commented 3 years ago

The documentation in the Terraform Registry is a little unclear about this, but the URL included in the provider must include the protocol. I had this same issue and solved it by adding https:// to my URL.

Here's his code:

provider "artifactory" { 
  url = "myorg.jfrog.io/artifactory"

Here's your code that works:

provider "artifactory" { 
  url = "https://partnership.jfrog.io/artifactory"

He didn't include the protocol, that's the difference.

chb0github commented 3 years ago

Frankly, after having read the error message, it was pretty clear - I just missed it. Side note: the /artifactory is no longer necessary as we now have support for xray and the path is determined by which service is neeeded

nc-andersenb commented 3 years ago

No problem. I was just calling it out for anyone else who ends up having this issue.