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

feat(registry): add tag data source #2696

Merged
merged 10 commits into from
Sep 18, 2024
Merged

feat(registry): add tag data source #2696

merged 10 commits into from
Sep 18, 2024

Conversation

pnodet
Copy link
Contributor

@pnodet pnodet commented Aug 8, 2024

No description provided.

@github-actions github-actions bot added the registry Managed Container Registry issues, bugs and feature requests label Aug 8, 2024
@remyleone
Copy link
Member

Hello and thanks a lot for contributing :)

I got some questions:

@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 2024

Codecov Report

Attention: Patch coverage is 51.06383% with 69 lines in your changes missing coverage. Please review.

Project coverage is 71.12%. Comparing base (fe86049) to head (0a4316a).
Report is 208 commits behind head on master.

Files with missing lines Patch % Lines
internal/services/registry/testfuncs/checks.go 0.00% 53 Missing ⚠️
internal/services/registry/tag_data_source.go 81.60% 11 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2696      +/-   ##
==========================================
- Coverage   71.43%   71.12%   -0.32%     
==========================================
  Files         277      338      +61     
  Lines       35875    33960    -1915     
==========================================
- Hits        25628    24154    -1474     
+ Misses       8028     7463     -565     
- Partials     2219     2343     +124     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pnodet
Copy link
Contributor Author

pnodet commented Aug 20, 2024

Hi @remyleone !

The idea behind this is to retrieve the digest of an image.

It can help in invalidating ressources on image updates even though the tag has not changed.

Some provider handle this for "latest" tags, but some control and flexibility is nice.

If I'm not mistaken the docker provider you mentioned needs a docker daemon to run, which adds some complexity... You can use tf to setup a scw instance, install docker on it, then run another terraform plan which will connect to it and pull the image data...

There are simpler ways to do it but since most of my tf plans are using this scw provider I thought it be simpler.

Do you have some specific concerns?

@pnodet
Copy link
Contributor Author

pnodet commented Aug 21, 2024

@remyleone Here is the workaround I'm currently using

terraform {
  required_version = "1.9.4"
  required_providers {
    http = {
      source  = "hashicorp/http"
      version = "3.4.4"
    }
  }
}

variable "region" {
  description = "Region of the image to retrieve"
  type        = string
  default     = "fr-par"
}

variable "scw_secret" {
  description = "Scaleway Secret"
  type        = string
  sensitive   = true
}

variable "tag" {
  description = "Tag of the image to retrieve"
  type        = string
  default     = "latest"
}

variable "image_id" {
  description = "id of the image to retrieve"
  type        = string
}

data "http" "registry_tags" {
  url = "https://api.scaleway.com/registry/v1/regions/${var.region}/images/${var.image_id}/tags?name=${var.tag}"

  request_headers = {
    "X-Auth-Token" = var.scw_secret
  }

  # {
  #   "tags": [
  #     {
  #       "id": "string",
  #       "name": "string",
  #       "image_id": "string",
  #       "status": "string",
  #       "digest": "string",
  #       "created_at": "string",
  #       "updated_at": "string"
  #     }
  #   ],
  #   "total_count": "integer"
  # }
}

output "image_id" {
  value = var.image_id
}

output "tag_id" {
  value = jsondecode(data.http.registry_tags.response_body).tags[0].id
}

output "tag_sha" {
  value = jsondecode(data.http.registry_tags.response_body).tags[0].digest
}

@remyleone
Copy link
Member

remyleone commented Aug 29, 2024

Ok I understand better your use case. I think documentation and tests are missing from this PR and we would need it to merge it. Otherwise this PR looks good :) thanks a lot for contributing :)

@pnodet
Copy link
Contributor Author

pnodet commented Aug 29, 2024

@remyleone Thanks! Will you handle docs and tests?

btw force pushed to rebase main and keep this branch up to date

@remyleone remyleone enabled auto-merge September 18, 2024 08:26
@remyleone remyleone added this pull request to the merge queue Sep 18, 2024
Merged via the queue into scaleway:master with commit f6912dd Sep 18, 2024
43 checks passed
@pnodet pnodet deleted the patch-1 branch September 18, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
registry Managed Container Registry issues, bugs and feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants