Skip to content

Commit

Permalink
feat: added gar repo creation
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhu34 committed Nov 10, 2023
1 parent 0909979 commit 1766c44
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 66 deletions.
30 changes: 30 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
driver:
name: terraform
verify_version: false

provisioner:
name: terraform

verifier:
name: terraform

platforms:
- name: default

suites:
- name: default
4 changes: 4 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# NOTE: This file is automatically generated from values at:
# https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/blob/master/infra/terraform/test-org/org/locals.tf

* @GoogleCloudPlatform/blueprint-solutions @prabhu34 @gtsorbo
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,29 @@ Functional examples are included in the

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| bucket\_name | The name of the bucket to create | `string` | n/a | yes |
| project\_id | The project ID to deploy to | `string` | n/a | yes |
| cleanup\_policies | Cleanup policies for this repository. Cleanup policies indicate when certain package versions can be automatically deleted. Map keys are policy IDs supplied by users during policy creation. They must unique within a repository and be under 128 characters in length. | <pre>map(object({<br> action = optional(string)<br> condition = optional(object({<br> tag_state = optional(string)<br> tag_prefixes = optional(list(string))<br> version_name_prefixes = optional(list(string))<br> package_name_prefixes = optional(list(string))<br> older_than = optional(string)<br> newer_than = optional(string)<br> }), null)<br> most_recent_versions = optional(object({<br> package_name_prefixes = optional(list(string))<br> keep_count = optional(number)<br> }), null)<br> }))</pre> | `{}` | no |
| cleanup\_policy\_dry\_run | If true, the cleanup pipeline is prevented from deleting versions in this repository | `bool` | `false` | no |
| description | The user-provided description of the repository | `string` | `null` | no |
| docker\_config | Docker repository config contains repository level configuration for the repositories of docker type | <pre>object({<br> immutable_tags = optional(bool)<br> })</pre> | `null` | no |
| format | The format of packages that are stored in the repository. You can only create alpha formats if you are a member of the alpha user group. | `string` | n/a | yes |
| kms\_key\_name | The Cloud KMS resource name of the customer managed encryption key that’s used to encrypt the contents of the Repository. Has the form: projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key. This value may not be changed after the Repository has been created | `string` | `null` | no |
| labels | Lables for the repository | `map(string)` | `{}` | no |
| location | The name of the location this repository is located in | `string` | n/a | yes |
| maven\_config | MavenRepositoryConfig is maven related repository details. Provides additional configuration details for repositories of the maven format type. | <pre>object({<br> allow_snapshot_overwrites = optional(bool)<br> version_policy = optional(string)<br> })</pre> | `null` | no |
| mode | The mode configures the repository to serve artifacts from different sources. Default value is STANDARD\_REPOSITORY. Possible values are: STANDARD\_REPOSITORY, VIRTUAL\_REPOSITORY, REMOTE\_REPOSITORY | `string` | `"STANDARD_REPOSITORY"` | no |
| project\_id | The project ID to create the repository | `string` | n/a | yes |
| remote\_repository\_config | Configuration specific for a Remote Repository. | <pre>object({<br> description = optional(string)<br> apt_repository = optional(object({<br> public_repository = optional(object({<br> repository_base = string<br> repository_path = string<br> }), null)<br> }), null)<br> docker_repository = optional(object({<br> public_repository = optional(string, "DOCKER_HUB")<br> }), null)<br> maven_repository = optional(object({<br> public_repository = optional(string, "MAVEN_CENTRAL")<br> }), null)<br> npm_repository = optional(object({<br> public_repository = optional(string, "NPMJS")<br> }), null)<br> python_repository = optional(object({<br> public_repository = optional(string, "PYPI")<br> }), null)<br> yum_repository = optional(object({<br> public_repository = optional(object({<br> repository_base = string<br> repository_path = string<br> }), null)<br> }), null)<br> })</pre> | `null` | no |
| repository\_id | The repository name | `string` | n/a | yes |
| virtual\_repository\_config | Configuration specific for a Virtual Repository. | <pre>object({<br> upstream_policies = optional(object({<br> id = string<br> repository = string<br> priority = number<br> }), null)<br> })</pre> | `null` | no |

## Outputs

| Name | Description |
|------|-------------|
| bucket\_name | Name of the bucket |
| artifact\_id | an identifier for the resource |
| artifact\_name | an identifier for the resource |
| create\_time | The time when the repository was created. |
| update\_time | The time when the repository was last updated. |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Simple Example
# Docker Repo

This example illustrates how to use the `artifact-registry` module.

Expand All @@ -7,14 +7,13 @@ This example illustrates how to use the `artifact-registry` module.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| bucket\_name | The name of the bucket to create. | `string` | n/a | yes |
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| bucket\_name | The name of the bucket. |
| artifact\_id | An identifier for the docker repo |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
module "artifact_registry" {
source = "../.."

project_id = var.project_id
bucket_name = var.bucket_name
project_id = var.project_id
location = "us-central1"
format = "DOCKER"
repository_id = "first-docker-repo"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

output "bucket_name" {
description = "The name of the bucket."
value = module.artifact_registry.bucket_name
output "artifact_id" {
description = "An identifier for the docker repo"
value = module.artifact_registry.artifact_id
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ variable "project_id" {
description = "The ID of the project in which to provision resources."
type = string
}

variable "bucket_name" {
description = "The name of the bucket to create."
type = string
}
File renamed without changes.
136 changes: 132 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,136 @@
* limitations under the License.
*/

resource "google_storage_bucket" "main" {
project = var.project_id
name = var.bucket_name
location = "US"
resource "google_artifact_registry_repository" "repo" {
provider = google-beta

repository_id = var.repository_id
location = var.location
format = var.format
project = var.project_id
mode = var.mode
description = var.description
labels = var.labels

kms_key_name = var.kms_key_name

dynamic "docker_config" {
for_each = var.docker_config[*]
content {
immutable_tags = docker_config.value.immutable_tags
}
}

dynamic "maven_config" {
for_each = var.maven_config[*]
content {
allow_snapshot_overwrites = maven_config.value.allow_snapshot_overwrites
version_policy = maven_config.value.version_policy
}
}

dynamic "virtual_repository_config" {
for_each = var.virtual_repository_config[*]
content {
dynamic "upstream_policies" {
for_each = virtual_repository_config.value.upstream_policies[*]
content {
id = upstream_policies.value.id
repository = upstream_policies.value.repository
priority = upstream_policies.value.priority
}
}
}
}

dynamic "remote_repository_config" {
for_each = var.remote_repository_config[*]
content {
description = remote_repository_config.value.description

dynamic "apt_repository" {
for_each = remote_repository_config.value.apt_repository[*]
content {
dynamic "public_repository" {
for_each = apt_repository.value.public_repository[*]
content {
repository_base = public_repository.value.repository_base
repository_path = public_repository.value.repository_path
}
}
}
}

dynamic "docker_repository" {
for_each = remote_repository_config.value.docker_repository[*]
content {
public_repository = docker_repository.value.public_repository
}
}

dynamic "maven_repository" {
for_each = remote_repository_config.value.maven_repository[*]
content {
public_repository = maven_repository.value.public_repository
}
}

dynamic "npm_repository" {
for_each = remote_repository_config.value.npm_repository[*]
content {
public_repository = npm_repository.value.public_repository
}
}

dynamic "python_repository" {
for_each = remote_repository_config.value.python_repository[*]
content {
public_repository = python_repository.value.public_repository
}
}

dynamic "yum_repository" {
for_each = remote_repository_config.value.yum_repository[*]
content {
dynamic "public_repository" {
for_each = yum_repository.value.public_repository[*]
content {
repository_base = public_repository.value.repository_base
repository_path = public_repository.value.repository_path
}
}
}
}
}
}

cleanup_policy_dry_run = var.cleanup_policy_dry_run

dynamic "cleanup_policies" {
for_each = var.cleanup_policies
content {
id = cleanup_policies.key
action = cleanup_policies.value.action

dynamic "condition" {
for_each = cleanup_policies.value.condition[*]
content {
tag_state = condition.value.tag_state
tag_prefixes = condition.value.tag_prefixes
older_than = condition.value.older_than
newer_than = condition.value.newer_than
version_name_prefixes = condition.value.version_name_prefixes
package_name_prefixes = condition.value.package_name_prefixes
}
}

dynamic "most_recent_versions" {
for_each = cleanup_policies.value.most_recent_versions[*]
content {
keep_count = most_recent_versions.value.keep_count
package_name_prefixes = most_recent_versions.value.package_name_prefixes
}
}
}
}
}
21 changes: 18 additions & 3 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@
* limitations under the License.
*/

output "bucket_name" {
description = "Name of the bucket"
value = google_storage_bucket.main.name
output "artifact_id" {
description = "an identifier for the resource"
value = google_artifact_registry_repository.repo.id
}

output "artifact_name" {
description = "an identifier for the resource"
value = google_artifact_registry_repository.repo.name
}

output "create_time" {
description = "The time when the repository was created."
value = google_artifact_registry_repository.repo.create_time
}

output "update_time" {
description = "The time when the repository was last updated."
value = google_artifact_registry_repository.repo.update_time
}
39 changes: 0 additions & 39 deletions test/integration/simple_example/simple_example_test.go

This file was deleted.

4 changes: 3 additions & 1 deletion test/setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module "project" {
activate_apis = [
"cloudresourcemanager.googleapis.com",
"storage-api.googleapis.com",
"serviceusage.googleapis.com"
"serviceusage.googleapis.com",
"artifactregistry.googleapis.com",
"secretmanager.googleapis.com"
]
}
Loading

0 comments on commit 1766c44

Please sign in to comment.