Skip to content

Commit

Permalink
Call GetProject
Browse files Browse the repository at this point in the history
  • Loading branch information
trodge committed Dec 19, 2023
1 parent cb05ebb commit 4163c36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion mmv1/products/cloudbuildv2/Repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async: !ruby/object:Api::OpAsync
base_url: '{{op_id}}'
description: "A repository associated to a parent connection."
exclude_tgc: true
legacy_long_form_project: true
examples:
# These tests depend on secrets stored in a separate project, so we prefer not
# to show them in the docs.
Expand Down Expand Up @@ -74,7 +75,7 @@ parameters:
url_param_only: true
required: true
immutable: true
diff_suppress_func: 'tpgresource.CompareResourceNames'
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
properties:
- !ruby/object:Api::Type::String
name: name
Expand Down
11 changes: 6 additions & 5 deletions mmv1/templates/terraform/encoders/cloudbuildv2_repository.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
config := meta.(*transport_tpg.Config)
// Extract any empty fields from the parent_connection field.
project := d.Get("project").(string)
project, err := tpgresource.GetProject(d, config)
if err != nil {
return nil, fmt.Errorf("error getting project: %s", err)
}
parent_connection := d.Get("parent_connection").(string)
project, err := tpgresource.ExtractFieldByPattern("project", project, parent_connection, "projects/([a-z0-9A-Z-]*)/locations/.*")
project, err = tpgresource.ExtractFieldByPattern("project", project, parent_connection, "projects/([a-z0-9A-Z-]*)/locations/.*")
if err != nil {
return nil, fmt.Errorf("error extracting project field: %s", err)
}
Expand All @@ -27,10 +31,7 @@ if err != nil {
// Set project to the extracted value.
d.Set("project", project)
// Set all the other fields to their short forms before forming url and setting ID.
parent_connection = tpgresource.GetResourceNameFromSelfLink(parent_connection)
name := d.Get("name").(string)
name = tpgresource.GetResourceNameFromSelfLink(name)
d.Set("location", location)
d.Set("parent_connection", parent_connection)
d.Set("name", name)
return obj, nil

0 comments on commit 4163c36

Please sign in to comment.