atlassian / terraform-provider-artifactory

Terraform provider to manage Artifactory
Apache License 2.0
89 stars 42 forks source link

datasources added: artifactory_file & artifactory_fileinfo #65

Closed volkc-basf closed 4 years ago

volkc-basf commented 4 years ago

This PR implements https://github.com/atlassian/terraform-provider-artifactory/issues/63, means it will add support to download artifacts using terraform. It won't compile as long as https://github.com/atlassian/go-artifactory/pull/19 is not merged.

Best, Chris

provider "artifactory" { ... } # this is up to you

data "artifactory_file" "test" {
   # required - the repository key
   repository = "repo-key" 

   # required - the path to the artifact within the repo
   path = "/path/to/the/artifact.zip" 

   # optional (default: empty)   - if set terraform will download the artifact to the specified output_path, if nil only the metadata (see below) are accessible
   output_path = "artifact.zip"

   # optional (default: false) - if true, terraform will overwrite the existing file specified via output_path
   force_overwrite = true                                                                 
}

output "created" {
  value = data.artifactory_file.test.created_by
}

output "created_by" {
  value = data.artifactory_file.test.created_by
}

output "last_modified" {
  value = data.artifactory_file.test.last_modified
}

output "modified_by" {
  value = data.artifactory_file.test.modified_by
}

output "last_updated" {
  value = data.artifactory_file.test.last_updated
}

output "mimetype" {
  value = data.artifactory_file.test.mimetype
}

output "size" {
  value = data.artifactory_file.test.size
}

output "uri" {
  value = data.artifactory_file.test.download_uri
}

output "md5" {
  value = data.artifactory_file.test.md5
}

output "sha1" {
  value = data.artifactory_file.test.sha1
}

output "sha256" {
  value = data.artifactory_file.test.sha256
}

output "output_path" {
  value = data.artifactory_file.test.output_path
}
volkc-basf commented 4 years ago

Just to give you an intuition how the output of the above hcl script could look like ... ;-)

image

volkc-basf commented 4 years ago

Hey @ttsangAtlassian,

may I ask you for an update? Please let me know if you do need any further help from my side.

Thanks, Chris

jamestoyer commented 4 years ago

@volkc-basf apologies. I will try and take a look today. I have noticed that the formatting is failing to pass in the build test. Could you fix that up?

volkc-basf commented 4 years ago

@jamestoyer Hope it's okay now.

jamestoyer commented 4 years ago

@volkc-basf I've gone ahead and released v2.5.0 of the go-artifactory client library. Could you update to it and check that everything works as expected? 🙂

volkc-basf commented 4 years ago

@jamestoyer: From my side, everything looks very good ;-)

volkc-basf commented 4 years ago

Looking through this I think what you really want are two data sources. One for the File Info and one to get the file.

Do you have a use case for that, where someone is only interested in file metadata? I mean Terraform is built to deploy certain things, hence I believe people are more interested in the raw file rather than in its metadata. But of course, one thing we could discuss is to make the output_path property mandatory.

jamestoyer commented 4 years ago

I can think of a few scenarios whereby you might only want one or the other

  1. You are using the file info to populate a template used by something else, e.g. userdata in an EC2 instance
  2. You might want to get the file info and conditionally download the file based on that information

In both scenarios you don't want the file at first, but may want it later. Having an optional field which modifies the download behaviour of the file feels like it's making the process more opaque.

volkc-basf commented 4 years ago

Okay, I don't mind. Added a second dataSource called _artifactoryfileinfo, that can be used to access the metadata only and in parallel I set the output_path in _artifactoryfile as required. Docs are also there now.

volkc-basf commented 4 years ago

@jamestoyer: The build is failing with "Please check your payment method or billing status.", could you please check that?

jamestoyer commented 4 years ago

😞

@ttsangAtlassian have actions been turned off for this repo?

volkc-basf commented 4 years ago

It looks good. I'll just wait for @ttsangAtlassian to check what's happened to the GitHub actions then we can get this merged.

Perfect, thank you for your help!

ttsangAtlassian commented 4 years ago

I have a bad feeling we are being bitten by this https://github.community/t5/GitHub-Actions/GitHub-Actions-workflows-can-t-be-executed-on-this-repository/td-p/38153 It looks like when actions went GA on Nov 14th, legacy plans had actions disabled for all plans including OSS. I'll try and chase this up

volkc-basf commented 4 years ago

I have a bad feeling we are being bitten by this https://github.community/t5/GitHub-Actions/GitHub-Actions-workflows-can-t-be-executed-on-this-repository/td-p/38153 It looks like when actions went GA on Nov 14th, legacy plans had actions disabled for all plans including OSS. I'll try and chase this up

@ttsangAtlassian: How is it? Hope you have some positive news for me l;-)

ttsangAtlassian commented 4 years ago

@volkc-basf I'm sorry we are still trying to work out what is happening with our licenses on our end. For now I am happy to remove the build checks to get this merged.