-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35174 from aristosvo/secretsmanager/aws-sdk-go-v2
`aws_secretsmanager_*` - migrate to `aws-sdk-go-v2`
- Loading branch information
Showing
47 changed files
with
1,883 additions
and
980 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
resource/aws_secretsmanager_secret_rotation: Add `rotate_immediately` argument | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:enhancement | ||
data-source/aws_secretsmanager_secret: Add `created_date` and `last_changed_date` attributes | ||
``` | ||
|
||
```release-note:enhancement | ||
data-source/aws_secretsmanager_secret_version: Add `created_date` attribute | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
internal/generate/namevaluesfilters/service_filters_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# namevaluesfiltersv2 | ||
|
||
The `namevaluesfiltersv2` package is designed to provide a consistent interface for handling AWS resource filtering for AWS SDK for Go v2. | ||
|
||
This package implements a single `NameValuesFilters` type, which covers all filter handling logic, such as merging filters, via functions on the single type. The underlying implementation is compatible with Go operations such as `len()`. | ||
|
||
Full documentation for this package can be found on [GoDoc](https://godoc.org/github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfiltersv2). | ||
|
||
Many AWS Go SDK v2 services that support resource filtering have their service-specific Go type conversion functions to and from `NameValuesFilters` code generated. Converting from `NameValuesFilters` to AWS Go SDK v2 types is done via `{SERVICE}Filters()` functions on the type. For more information about this code generation, see the [`generators/servicefilters` README](generators/servicefilters/README.md). | ||
|
||
Any filtering functions that cannot be generated should be hand implemented in a service-specific source file and follow the format of similar generated code wherever possible. The first line of the source file should be `// +build !generate`. This prevents the file's inclusion during the code generation phase. | ||
|
||
## Code Structure | ||
|
||
```text | ||
internal/generate/namevaluesfiltersv2 | ||
├── generators | ||
│ └── servicefilters (generates service_filters_gen.go) | ||
├── name_values_filters_test.go (unit tests for core logic) | ||
├── name_values_filters.go (core logic) | ||
├── service_generation_customizations.go (shared AWS Go SDK service customizations for generators) | ||
├── service_filters_gen.go (generated AWS Go SDK service conversion functions) | ||
└── <service name>_filters.go (any service-specific functions that cannot be generated) | ||
``` |
42 changes: 42 additions & 0 deletions
42
internal/generate/namevaluesfiltersv2/generators/servicefilters/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# servicefilters | ||
|
||
This package contains a code generator to consistently handle the various AWS Go SDK service implementations for converting service filter types to/from `NameValuesFilters`. Not all AWS Go SDK services that support filters are generated in this manner. | ||
|
||
To run this code generator, execute `go generate ./...` from the root of the repository. The general workflow for the generator is: | ||
|
||
- Generate Go file contents via template from local variables and functions | ||
- Go format file contents | ||
- Write file contents to `service_filters_gen.go` file | ||
|
||
## Example Output | ||
|
||
```go | ||
// DocDBFilters returns docdb service filters. | ||
func (filters NameValuesFilters) DocDBFilters() []*docdb.Filter { | ||
m := filters.Map() | ||
|
||
if len(m) == 0 { | ||
return nil | ||
} | ||
|
||
result := make([]*docdb.Filter, 0, len(m)) | ||
|
||
for k, v := range m { | ||
filter := &docdb.Filter{ | ||
Name: aws.String(k), | ||
Values: aws.StringSlice(v), | ||
} | ||
|
||
result = append(result, filter) | ||
} | ||
|
||
return result | ||
} | ||
``` | ||
|
||
## Implementing a New Generated Service | ||
|
||
- In `main.go`: Add service name, e.g. `docdb`, to one of the implementation handlers | ||
- Use `sliceServiceNames` if the AWS Go SDK service implements a specific Go type such as `Filter` | ||
- Run `go generate ./...` (or `make gen`) from the root of the repository to regenerate the code | ||
- Run `go test ./...` (or `make test`) from the root of the repository to ensure the generated code compiles |
117 changes: 117 additions & 0 deletions
117
internal/generate/namevaluesfiltersv2/generators/servicefilters/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//go:build generate | ||
// +build generate | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"go/format" | ||
"log" | ||
"os" | ||
"sort" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfiltersv2" | ||
) | ||
|
||
const filename = `service_filters_v2_gen.go` | ||
|
||
// Representing types such as []*ec2.Filter, []*rds.Filter, ... | ||
var sliceServiceNames = []string{ | ||
"secretsmanager", | ||
} | ||
|
||
type TemplateData struct { | ||
SliceServiceNames []string | ||
} | ||
|
||
func main() { | ||
// Always sort to reduce any potential generation churn | ||
sort.Strings(sliceServiceNames) | ||
|
||
templateData := TemplateData{ | ||
SliceServiceNames: sliceServiceNames, | ||
} | ||
templateFuncMap := template.FuncMap{ | ||
"FilterPackage": namevaluesfiltersv2.ServiceFilterPackage, | ||
"FilterPackagePrefix": namevaluesfiltersv2.ServiceFilterPackagePrefix, | ||
"FilterType": namevaluesfiltersv2.ServiceFilterType, | ||
"FilterTypeNameField": namevaluesfiltersv2.ServiceFilterTypeNameField, | ||
"FilterTypeValuesField": namevaluesfiltersv2.ServiceFilterTypeValuesField, | ||
"Title": strings.Title, | ||
} | ||
|
||
tmpl, err := template.New("servicefilters").Funcs(templateFuncMap).Parse(templateBody) | ||
|
||
if err != nil { | ||
log.Fatalf("error parsing template: %s", err) | ||
} | ||
|
||
var buffer bytes.Buffer | ||
err = tmpl.Execute(&buffer, templateData) | ||
|
||
if err != nil { | ||
log.Fatalf("error executing template: %s", err) | ||
} | ||
|
||
generatedFileContents, err := format.Source(buffer.Bytes()) | ||
|
||
if err != nil { | ||
log.Fatalf("error formatting generated file: %s", err) | ||
} | ||
|
||
f, err := os.Create(filename) | ||
|
||
if err != nil { | ||
log.Fatalf("error creating file (%s): %s", filename, err) | ||
} | ||
|
||
defer f.Close() | ||
|
||
_, err = f.Write(generatedFileContents) | ||
|
||
if err != nil { | ||
log.Fatalf("error writing to file (%s): %s", filename, err) | ||
} | ||
} | ||
|
||
var templateBody = ` | ||
// Code generated by generators/servicefilters/main.go; DO NOT EDIT. | ||
package namevaluesfiltersv2 | ||
import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports | ||
{{- range .SliceServiceNames }} | ||
{{- if eq . (. | FilterPackage) }} | ||
{{ . }} | ||
{{- end }} | ||
{{- end }} | ||
) | ||
// []*SERVICE.Filter handling | ||
{{- range .SliceServiceNames }} | ||
// {{ . | Title }}Filters returns {{ . }} service filters. | ||
func (filters NameValuesFilters) {{ . | Title }}Filters() []*{{ . | FilterPackagePrefix }}.{{ . | FilterType }} { | ||
m := filters.Map() | ||
if len(m) == 0 { | ||
return nil | ||
} | ||
result := make([]{{ . | FilterPackagePrefix }}.{{ . | FilterType }}, 0, len(m)) | ||
for k, v := range m { | ||
filter := {{ . | FilterPackagePrefix }}.{{ . | FilterType }}{ | ||
{{ . | FilterTypeNameField }}: { . | FilterPackagePrefix }}.FilterNameStringType(k), | ||
{{ . | FilterTypeValuesField }}: v, | ||
} | ||
result = append(result, filter) | ||
} | ||
return result | ||
} | ||
{{- end }} | ||
` |
Oops, something went wrong.