diff --git a/.changelog/9460.txt b/.changelog/9460.txt new file mode 100644 index 0000000000..e58381d05e --- /dev/null +++ b/.changelog/9460.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +cloudbuild: added fields `build.artifacts.maven_artifacts`, `build.artifacts.npm_packages `, and `build.artifacts.python_packages ` to resource `google_cloudbuild_trigger` +``` diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go b/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go index 919c15d560..a10230462c 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go +++ b/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go @@ -417,6 +417,71 @@ If any of the images fail to be pushed, the build is marked FAILURE.`, Type: schema.TypeString, }, }, + "maven_artifacts": { + Type: schema.TypeList, + Optional: true, + Description: `A Maven artifact to upload to Artifact Registry upon successful completion of all build steps. + +The location and generation of the uploaded objects will be stored in the Build resource's results field. + +If any objects fail to be pushed, the build is marked FAILURE.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "artifact_id": { + Type: schema.TypeString, + Optional: true, + Description: `Maven artifactId value used when uploading the artifact to Artifact Registry.`, + }, + "group_id": { + Type: schema.TypeString, + Optional: true, + Description: `Maven groupId value used when uploading the artifact to Artifact Registry.`, + }, + "path": { + Type: schema.TypeString, + Optional: true, + Description: `Path to an artifact in the build's workspace to be uploaded to Artifact Registry. This can be either an absolute path, e.g. /workspace/my-app/target/my-app-1.0.SNAPSHOT.jar or a relative path from /workspace, e.g. my-app/target/my-app-1.0.SNAPSHOT.jar.`, + }, + "repository": { + Type: schema.TypeString, + Optional: true, + Description: `Artifact Registry repository, in the form "https://$REGION-maven.pkg.dev/$PROJECT/$REPOSITORY" + +Artifact in the workspace specified by path will be uploaded to Artifact Registry with this location as a prefix.`, + }, + "version": { + Type: schema.TypeString, + Optional: true, + Description: `Maven version value used when uploading the artifact to Artifact Registry.`, + }, + }, + }, + }, + "npm_packages": { + Type: schema.TypeList, + Optional: true, + Description: `Npm package to upload to Artifact Registry upon successful completion of all build steps. + +The location and generation of the uploaded objects will be stored in the Build resource's results field. + +If any objects fail to be pushed, the build is marked FAILURE.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "package_path": { + Type: schema.TypeString, + Optional: true, + Description: `Path to the package.json. e.g. workspace/path/to/package`, + }, + "repository": { + Type: schema.TypeString, + Optional: true, + Description: `Artifact Registry repository, in the form "https://$REGION-npm.pkg.dev/$PROJECT/$REPOSITORY" + +Npm package in the workspace specified by path will be zipped and uploaded to Artifact Registry with this location as a prefix.`, + }, + }, + }, + }, "objects": { Type: schema.TypeList, Optional: true, @@ -475,6 +540,34 @@ nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:2 }, }, }, + "python_packages": { + Type: schema.TypeList, + Optional: true, + Description: `Python package to upload to Artifact Registry upon successful completion of all build steps. A package can encapsulate multiple objects to be uploaded to a single repository. + +The location and generation of the uploaded objects will be stored in the Build resource's results field. + +If any objects fail to be pushed, the build is marked FAILURE.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "paths": { + Type: schema.TypeList, + Optional: true, + Description: `Path globs used to match files in the build's workspace. For Python/ Twine, this is usually dist/*, and sometimes additionally an .asc file.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "repository": { + Type: schema.TypeString, + Optional: true, + Description: `Artifact Registry repository, in the form "https://$REGION-python.pkg.dev/$PROJECT/$REPOSITORY" + +Files in the workspace matching any path pattern will be uploaded to Artifact Registry with this location as a prefix.`, + }, + }, + }, + }, }, }, }, @@ -2786,6 +2879,12 @@ func flattenCloudBuildTriggerBuildArtifacts(v interface{}, d *schema.ResourceDat flattenCloudBuildTriggerBuildArtifactsImages(original["images"], d, config) transformed["objects"] = flattenCloudBuildTriggerBuildArtifactsObjects(original["objects"], d, config) + transformed["maven_artifacts"] = + flattenCloudBuildTriggerBuildArtifactsMavenArtifacts(original["mavenArtifacts"], d, config) + transformed["python_packages"] = + flattenCloudBuildTriggerBuildArtifactsPythonPackages(original["pythonPackages"], d, config) + transformed["npm_packages"] = + flattenCloudBuildTriggerBuildArtifactsNpmPackages(original["npmPackages"], d, config) return []interface{}{transformed} } func flattenCloudBuildTriggerBuildArtifactsImages(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { @@ -2840,6 +2939,102 @@ func flattenCloudBuildTriggerBuildArtifactsObjectsTimingEndTime(v interface{}, d return v } +func flattenCloudBuildTriggerBuildArtifactsMavenArtifacts(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "repository": flattenCloudBuildTriggerBuildArtifactsMavenArtifactsRepository(original["repository"], d, config), + "path": flattenCloudBuildTriggerBuildArtifactsMavenArtifactsPath(original["path"], d, config), + "artifact_id": flattenCloudBuildTriggerBuildArtifactsMavenArtifactsArtifactId(original["artifactId"], d, config), + "group_id": flattenCloudBuildTriggerBuildArtifactsMavenArtifactsGroupId(original["groupId"], d, config), + "version": flattenCloudBuildTriggerBuildArtifactsMavenArtifactsVersion(original["version"], d, config), + }) + } + return transformed +} +func flattenCloudBuildTriggerBuildArtifactsMavenArtifactsRepository(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudBuildTriggerBuildArtifactsMavenArtifactsPath(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudBuildTriggerBuildArtifactsMavenArtifactsArtifactId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudBuildTriggerBuildArtifactsMavenArtifactsGroupId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudBuildTriggerBuildArtifactsMavenArtifactsVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudBuildTriggerBuildArtifactsPythonPackages(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "repository": flattenCloudBuildTriggerBuildArtifactsPythonPackagesRepository(original["repository"], d, config), + "paths": flattenCloudBuildTriggerBuildArtifactsPythonPackagesPaths(original["paths"], d, config), + }) + } + return transformed +} +func flattenCloudBuildTriggerBuildArtifactsPythonPackagesRepository(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudBuildTriggerBuildArtifactsPythonPackagesPaths(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudBuildTriggerBuildArtifactsNpmPackages(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "repository": flattenCloudBuildTriggerBuildArtifactsNpmPackagesRepository(original["repository"], d, config), + "package_path": flattenCloudBuildTriggerBuildArtifactsNpmPackagesPackagePath(original["packagePath"], d, config), + }) + } + return transformed +} +func flattenCloudBuildTriggerBuildArtifactsNpmPackagesRepository(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudBuildTriggerBuildArtifactsNpmPackagesPackagePath(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenCloudBuildTriggerBuildOptions(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return nil @@ -4434,6 +4629,27 @@ func expandCloudBuildTriggerBuildArtifacts(v interface{}, d tpgresource.Terrafor transformed["objects"] = transformedObjects } + transformedMavenArtifacts, err := expandCloudBuildTriggerBuildArtifactsMavenArtifacts(original["maven_artifacts"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedMavenArtifacts); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["mavenArtifacts"] = transformedMavenArtifacts + } + + transformedPythonPackages, err := expandCloudBuildTriggerBuildArtifactsPythonPackages(original["python_packages"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPythonPackages); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["pythonPackages"] = transformedPythonPackages + } + + transformedNpmPackages, err := expandCloudBuildTriggerBuildArtifactsNpmPackages(original["npm_packages"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedNpmPackages); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["npmPackages"] = transformedNpmPackages + } + return transformed, nil } @@ -4516,6 +4732,150 @@ func expandCloudBuildTriggerBuildArtifactsObjectsTimingEndTime(v interface{}, d return v, nil } +func expandCloudBuildTriggerBuildArtifactsMavenArtifacts(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedRepository, err := expandCloudBuildTriggerBuildArtifactsMavenArtifactsRepository(original["repository"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRepository); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["repository"] = transformedRepository + } + + transformedPath, err := expandCloudBuildTriggerBuildArtifactsMavenArtifactsPath(original["path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPath); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["path"] = transformedPath + } + + transformedArtifactId, err := expandCloudBuildTriggerBuildArtifactsMavenArtifactsArtifactId(original["artifact_id"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedArtifactId); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["artifactId"] = transformedArtifactId + } + + transformedGroupId, err := expandCloudBuildTriggerBuildArtifactsMavenArtifactsGroupId(original["group_id"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedGroupId); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["groupId"] = transformedGroupId + } + + transformedVersion, err := expandCloudBuildTriggerBuildArtifactsMavenArtifactsVersion(original["version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["version"] = transformedVersion + } + + req = append(req, transformed) + } + return req, nil +} + +func expandCloudBuildTriggerBuildArtifactsMavenArtifactsRepository(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerBuildArtifactsMavenArtifactsPath(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerBuildArtifactsMavenArtifactsArtifactId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerBuildArtifactsMavenArtifactsGroupId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerBuildArtifactsMavenArtifactsVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerBuildArtifactsPythonPackages(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedRepository, err := expandCloudBuildTriggerBuildArtifactsPythonPackagesRepository(original["repository"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRepository); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["repository"] = transformedRepository + } + + transformedPaths, err := expandCloudBuildTriggerBuildArtifactsPythonPackagesPaths(original["paths"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPaths); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["paths"] = transformedPaths + } + + req = append(req, transformed) + } + return req, nil +} + +func expandCloudBuildTriggerBuildArtifactsPythonPackagesRepository(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerBuildArtifactsPythonPackagesPaths(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerBuildArtifactsNpmPackages(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedRepository, err := expandCloudBuildTriggerBuildArtifactsNpmPackagesRepository(original["repository"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRepository); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["repository"] = transformedRepository + } + + transformedPackagePath, err := expandCloudBuildTriggerBuildArtifactsNpmPackagesPackagePath(original["package_path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPackagePath); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["packagePath"] = transformedPackagePath + } + + req = append(req, transformed) + } + return req, nil +} + +func expandCloudBuildTriggerBuildArtifactsNpmPackagesRepository(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudBuildTriggerBuildArtifactsNpmPackagesPackagePath(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandCloudBuildTriggerBuildOptions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_trigger_generated_test.go b/google-beta/services/cloudbuild/resource_cloudbuild_trigger_generated_test.go index 8f27190e7d..2791e0c1c8 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_trigger_generated_test.go +++ b/google-beta/services/cloudbuild/resource_cloudbuild_trigger_generated_test.go @@ -155,6 +155,24 @@ resource "google_cloudbuild_trigger" "build-trigger" { location = "gs://bucket/path/to/somewhere/" paths = ["path"] } + + npm_packages { + package_path = "package.json" + repository = "https://us-west1-npm.pkg.dev/myProject/quickstart-nodejs-repo" + } + + python_packages { + paths = ["dist/*"] + repository = "https://us-west1-python.pkg.dev/myProject/quickstart-python-repo" + } + + maven_artifacts { + repository = "https://us-west1-maven.pkg.dev/myProject/quickstart-java-repo" + path = "/workspace/my-app/target/my-app-1.0.SNAPSHOT.jar" + artifact_id = "my-app" + group_id = "com.mycompany.app" + version = "1.0" + } } options { source_provenance_hash = ["MD5"] diff --git a/website/docs/r/cloudbuild_trigger.html.markdown b/website/docs/r/cloudbuild_trigger.html.markdown index b8efaf13de..f3bcaa5d0e 100644 --- a/website/docs/r/cloudbuild_trigger.html.markdown +++ b/website/docs/r/cloudbuild_trigger.html.markdown @@ -117,6 +117,24 @@ resource "google_cloudbuild_trigger" "build-trigger" { location = "gs://bucket/path/to/somewhere/" paths = ["path"] } + + npm_packages { + package_path = "package.json" + repository = "https://us-west1-npm.pkg.dev/myProject/quickstart-nodejs-repo" + } + + python_packages { + paths = ["dist/*"] + repository = "https://us-west1-python.pkg.dev/myProject/quickstart-python-repo" + } + + maven_artifacts { + repository = "https://us-west1-maven.pkg.dev/myProject/quickstart-java-repo" + path = "/workspace/my-app/target/my-app-1.0.SNAPSHOT.jar" + artifact_id = "my-app" + group_id = "com.mycompany.app" + version = "1.0" + } } options { source_provenance_hash = ["MD5"] @@ -1490,6 +1508,27 @@ The following arguments are supported: If any objects fail to be pushed, the build is marked FAILURE. Structure is [documented below](#nested_objects). +* `maven_artifacts` - + (Optional) + A Maven artifact to upload to Artifact Registry upon successful completion of all build steps. + The location and generation of the uploaded objects will be stored in the Build resource's results field. + If any objects fail to be pushed, the build is marked FAILURE. + Structure is [documented below](#nested_maven_artifacts). + +* `python_packages` - + (Optional) + Python package to upload to Artifact Registry upon successful completion of all build steps. A package can encapsulate multiple objects to be uploaded to a single repository. + The location and generation of the uploaded objects will be stored in the Build resource's results field. + If any objects fail to be pushed, the build is marked FAILURE. + Structure is [documented below](#nested_python_packages). + +* `npm_packages` - + (Optional) + Npm package to upload to Artifact Registry upon successful completion of all build steps. + The location and generation of the uploaded objects will be stored in the Build resource's results field. + If any objects fail to be pushed, the build is marked FAILURE. + Structure is [documented below](#nested_npm_packages). + The `objects` block supports: @@ -1523,6 +1562,51 @@ The following arguments are supported: A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". +The `maven_artifacts` block supports: + +* `repository` - + (Optional) + Artifact Registry repository, in the form "https://$REGION-maven.pkg.dev/$PROJECT/$REPOSITORY" + Artifact in the workspace specified by path will be uploaded to Artifact Registry with this location as a prefix. + +* `path` - + (Optional) + Path to an artifact in the build's workspace to be uploaded to Artifact Registry. This can be either an absolute path, e.g. /workspace/my-app/target/my-app-1.0.SNAPSHOT.jar or a relative path from /workspace, e.g. my-app/target/my-app-1.0.SNAPSHOT.jar. + +* `artifact_id` - + (Optional) + Maven artifactId value used when uploading the artifact to Artifact Registry. + +* `group_id` - + (Optional) + Maven groupId value used when uploading the artifact to Artifact Registry. + +* `version` - + (Optional) + Maven version value used when uploading the artifact to Artifact Registry. + +The `python_packages` block supports: + +* `repository` - + (Optional) + Artifact Registry repository, in the form "https://$REGION-python.pkg.dev/$PROJECT/$REPOSITORY" + Files in the workspace matching any path pattern will be uploaded to Artifact Registry with this location as a prefix. + +* `paths` - + (Optional) + Path globs used to match files in the build's workspace. For Python/ Twine, this is usually dist/*, and sometimes additionally an .asc file. + +The `npm_packages` block supports: + +* `repository` - + (Optional) + Artifact Registry repository, in the form "https://$REGION-npm.pkg.dev/$PROJECT/$REPOSITORY" + Npm package in the workspace specified by path will be zipped and uploaded to Artifact Registry with this location as a prefix. + +* `package_path` - + (Optional) + Path to the package.json. e.g. workspace/path/to/package + The `options` block supports: * `source_provenance_hash` -