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

Docker registry support for Cloud Functions #11729

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6040.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudfunctions: docker registry support for Cloud Functions
```
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ resource "google_clouddeploy_delivery_pipeline" "primary" {
name = "tf-test-pipeline%{random_suffix}"

annotations = {
my_first_annotation = "example-annotation-1"

my_second_annotation = "example-annotation-2"

my_first_annotation = "example-annotation-1"
}

description = "basic description"
Expand Down
16 changes: 8 additions & 8 deletions google/resource_clouddeploy_target_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ resource "google_clouddeploy_target" "primary" {
}

labels = {
my_third_label = "example-label-3"

my_second_label = "updated-example-label-2"

my_third_label = "example-label-3"
}

project = "%{project_name}"
Expand All @@ -156,9 +156,9 @@ resource "google_clouddeploy_target" "primary" {
name = "tf-test-target%{random_suffix}"

annotations = {
my_second_annotation = "updated-example-annotation-2"

my_third_annotation = "example-annotation-3"

my_second_annotation = "updated-example-annotation-2"
}

description = "updated description"
Expand Down Expand Up @@ -241,9 +241,9 @@ resource "google_clouddeploy_target" "primary" {
name = "tf-test-target%{random_suffix}"

annotations = {
my_third_annotation = "example-annotation-3"

my_second_annotation = "updated-example-annotation-2"

my_third_annotation = "example-annotation-3"
}

description = "updated description"
Expand All @@ -267,9 +267,9 @@ resource "google_clouddeploy_target" "primary" {
}

labels = {
my_third_label = "example-label-3"

my_second_label = "updated-example-label-2"

my_third_label = "example-label-3"
}

project = "%{project_name}"
Expand Down
19 changes: 19 additions & 0 deletions google/resource_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ func resourceCloudFunctionsFunction() *schema.Resource {
},
},

"docker_registry": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `Docker Registry to use for storing the function's Docker images. Allowed values are CONTAINER_REGISTRY (default) and ARTIFACT_REGISTRY.`,
},

"docker_repository": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -518,6 +525,10 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro
function.VpcConnectorEgressSettings = v.(string)
}

if v, ok := d.GetOk("docker_registry"); ok {
function.DockerRegistry = v.(string)
}

if v, ok := d.GetOk("docker_repository"); ok {
function.DockerRepository = v.(string)
}
Expand Down Expand Up @@ -660,6 +671,9 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("event_trigger", flattenEventTrigger(function.EventTrigger)); err != nil {
return fmt.Errorf("Error setting event_trigger: %s", err)
}
if err := d.Set("docker_registry", function.DockerRegistry); err != nil {
return fmt.Errorf("Error setting docker_registry: %s", err)
}
if err := d.Set("docker_repository", function.DockerRepository); err != nil {
return fmt.Errorf("Error setting docker_repository: %s", err)
}
Expand Down Expand Up @@ -796,6 +810,11 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
updateMaskArr = append(updateMaskArr, "httpsTrigger", "httpsTrigger.securityLevel")
}

if d.HasChange("docker_registry") {
function.DockerRegistry = d.Get("docker_registry").(string)
updateMaskArr = append(updateMaskArr, "dockerRegistry")
}

if d.HasChange("docker_repository") {
function.Runtime = d.Get("docker_repository").(string)
updateMaskArr = append(updateMaskArr, "dockerRepository")
Expand Down
6 changes: 6 additions & 0 deletions google/resource_cloudfunctions_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func TestAccCloudFunctionsFunction_basic(t *testing.T) {
"name", functionName),
resource.TestCheckResourceAttr(funcResourceName,
"description", "test function"),
resource.TestCheckResourceAttr(funcResourceName,
"docker_registry", "CONTAINER_REGISTRY"),
resource.TestCheckResourceAttr(funcResourceName,
"available_memory_mb", "128"),
resource.TestCheckResourceAttr(funcResourceName,
Expand Down Expand Up @@ -215,6 +217,8 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) {
"available_memory_mb", "256"),
resource.TestCheckResourceAttr(funcResourceName,
"description", "test function updated"),
resource.TestCheckResourceAttr(funcResourceName,
"docker_registry", "CONTAINER_REGISTRY"),
resource.TestCheckResourceAttr(funcResourceName,
"timeout", "91"),
resource.TestCheckResourceAttr(funcResourceName,
Expand Down Expand Up @@ -695,6 +699,7 @@ resource "google_cloudfunctions_function" "function" {
name = "%s"
runtime = "nodejs10"
description = "test function"
docker_registry = "CONTAINER_REGISTRY"
available_memory_mb = 128
source_archive_bucket = google_storage_bucket.bucket.name
source_archive_object = google_storage_bucket_object.archive.name
Expand Down Expand Up @@ -733,6 +738,7 @@ resource "google_storage_bucket_object" "archive" {
resource "google_cloudfunctions_function" "function" {
name = "%s"
description = "test function updated"
docker_registry = "CONTAINER_REGISTRY"
available_memory_mb = 256
source_archive_bucket = google_storage_bucket.bucket.name
source_archive_object = google_storage_bucket_object.archive.name
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/clouddeploy_delivery_pipeline.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ resource "google_clouddeploy_delivery_pipeline" "primary" {
name = "pipeline"

annotations = {
my_first_annotation = "example-annotation-1"

my_second_annotation = "example-annotation-2"

my_first_annotation = "example-annotation-1"
}

description = "basic description"
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cloudfunctions_function.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ Eg. `"nodejs16"`, `"python39"`, `"dotnet3"`, `"go116"`, `"java11"`, `"ruby30"`,
* `source_repository` - (Optional) Represents parameters related to source repository where a function is hosted.
Cannot be set alongside `source_archive_bucket` or `source_archive_object`. Structure is [documented below](#nested_source_repository). It must match the pattern `projects/{project}/locations/{location}/repositories/{repository}`.*

* `docker_registry` - (Optional) Docker Registry to use for storing the function's Docker images. Allowed values are CONTAINER_REGISTRY (default) and ARTIFACT_REGISTRY.

* `docker_repository` - (Optional) User managed repository created in Artifact Registry optionally with a customer managed encryption key. If specified, deployments will use Artifact Registry. This is the repository to which the function docker image will be pushed after it is built by Cloud Build. If unspecified, Container Registry will be used by default, unless specified otherwise by other means.

* `kms_key_name` - (Optional) Resource name of a KMS crypto key (managed by the user) used to encrypt/decrypt function resources. It must match the pattern `projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}`.
Expand Down