Skip to content

Add support for reading metadata.yaml in CFT-format, fallack to har…#1841

Merged
mr0re1 merged 1 commit into
GoogleCloudPlatform:developfrom
mr0re1:mtd
Oct 15, 2023
Merged

Add support for reading metadata.yaml in CFT-format, fallack to har…#1841
mr0re1 merged 1 commit into
GoogleCloudPlatform:developfrom
mr0re1:mtd

Conversation

@mr0re1

@mr0re1 mr0re1 commented Oct 14, 2023

Copy link
Copy Markdown
Collaborator

…dcoded logic.

  • Remove RequiredApis from ModuleInfo, replace with Metadata;
  • Refactor resreader_test.go to re-use embedded files for localFS test;
  • Use LastIndex instead Index on module source trimming to avoid potential errors;
  • Move defaultAPIList to metadata_legacy.go.

Created BP:

...
- id: gg
  source: github.com/terraform-google-modules/terraform-google-vm//modules/mig

Modified metadata.go:GetMetadataSafe:

panic(fmt.Sprintf("%#v", mtd.Spec.Requirements.Services))

Got:

> make && ./ghpc create gg.yaml
panic: []string{"cloudresourcemanager.googleapis.com", "storage-api.googleapis.com", "serviceusage.googleapis.com", "compute.googleapis.com", "iam.googleapis.com"}

Matches: https://github.com/terraform-google-modules/terraform-google-vm/blob/master/modules/mig/metadata.yaml#L294

@tpdownes tpdownes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function GetMetadata does not appear to error if I give an invalid format. For example, if I add community/modules/scheduler/schedmd-slurm-gcp-v5-controller/metadata.yaml with this content:

spec:
  requirements:
    services: yadayadayada

it returns a nil error and the empty list for mtd.Spec.Requirements.Services.

Other than that, I believe this is a very valuable addition to the Toolkit.

Please also add a label to the PR that will include it in the release notes.

@tpdownes tpdownes assigned mr0re1 and unassigned tpdownes Oct 14, 2023
…dcoded logic.

* Remove `RequiredApis` from `ModuleInfo`, replace with `Metadata`;
* Refactor `resreader_test.go` to re-use embedded files for localFS test;
* Use `LastIndex` instead `Index` on module source trimming to avoid potential errors;
* Move `defaultAPIList` to `metadata_legacy.go`.

Created BP:

```yaml
...
- id: gg
  source: github.com/terraform-google-modules/terraform-google-vm//modules/mig
```

Modified `metadata.go:GetMetadataSafe`:

```go
panic(fmt.Sprintf("%#v", mtd.Spec.Requirements.Services))
```

Got:

```sh
> make && ./ghpc create gg.yaml
panic: []string{"cloudresourcemanager.googleapis.com", "storage-api.googleapis.com", "serviceusage.googleapis.com", "compute.googleapis.com", "iam.googleapis.com"}
```

Matches: https://github.com/terraform-google-modules/terraform-google-vm/blob/master/modules/mig/metadata.yaml#L294
@mr0re1

mr0re1 commented Oct 14, 2023

Copy link
Copy Markdown
Collaborator Author

@tpdownes thank you for being so thorough with review! There was a typo, fixed.

@mr0re1 mr0re1 requested a review from tpdownes October 14, 2023 02:48
@mr0re1 mr0re1 assigned tpdownes and unassigned mr0re1 Oct 14, 2023
@mr0re1 mr0re1 added the release-improvements Added to release notes under the "Improvements" heading. label Oct 14, 2023

@tpdownes tpdownes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change will certainly do it. LGTM.

@tpdownes tpdownes assigned mr0re1 and unassigned tpdownes Oct 14, 2023
@mr0re1 mr0re1 merged commit c95399d into GoogleCloudPlatform:develop Oct 15, 2023
@mr0re1 mr0re1 deleted the mtd branch October 15, 2023 03:59
@mr0re1 mr0re1 mentioned this pull request Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-improvements Added to release notes under the "Improvements" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants