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

new resource: aws_ssm_default_patch_baseline #27610

Merged
merged 15 commits into from
Nov 3, 2022
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/27610.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_ssm_default_patch_baseline
```
4 changes: 4 additions & 0 deletions .ci/.semgrep-configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ rules:
patterns:
- pattern-not-regex: "testAcc[a-zA-Z0-9]+Config(_[a-zA-Z0-9_]+_|_)[a-z0-9].*"
- pattern-not: acctest.ConfigCompose(...)
- pattern-not: "..."
severity: WARNING

- id: test-configcompose-funcs-correct-form
languages:
- go
Expand All @@ -40,6 +42,7 @@ rules:
- pattern-not-regex: "testAcc[a-zA-Z0-9]+Config(_[a-zA-Z0-9_]+_|_)[a-z0-9].*"
- pattern-not-regex: "acctest\\..*"
severity: WARNING

- id: test-config-funcs-check
languages:
- go
Expand All @@ -59,6 +62,7 @@ rules:
patterns:
- pattern-regex: "testAccCheck.*"
severity: WARNING

- id: test-configcompose-funcs-check
languages:
- go
Expand Down
2 changes: 2 additions & 0 deletions .ci/.semgrep-service-name3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,8 @@ rules:
metavariable: $NAME
patterns:
- pattern-regex: "(?i)SSM"
- pattern-not-regex: ^testAccSSMDefaultPatchBaseline_.+
- pattern-not-regex: ^testAccSSMPatchBaseline_.+
- pattern-not-regex: ^TestAcc.*
severity: WARNING
- id: ssm-in-test-name
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/iam v1.18.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.19 // indirect
github.com/aws/aws-sdk-go-v2/service/ssm v1.31.3
github.com/aws/aws-sdk-go-v2/service/sso v1.11.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.4 // indirect
github.com/aws/smithy-go v1.13.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ github.com/aws/aws-sdk-go-v2/service/s3control v1.25.0 h1:f71DbTsBMbfqSr6XnFz64c
github.com/aws/aws-sdk-go-v2/service/s3control v1.25.0/go.mod h1:F2RWJqngKxHGxZUYA4jt/veKlbyXEpgSMZ67VyVpSEg=
github.com/aws/aws-sdk-go-v2/service/sesv2 v1.15.0 h1:I/EKJDC0fQTlUE656GEBSsrvwYSDd22EKxuXk46kFIU=
github.com/aws/aws-sdk-go-v2/service/sesv2 v1.15.0/go.mod h1:IeH7fIK+ReovHp+9rw9n5xxsxg5dDMLPF0DnL0AjPZc=
github.com/aws/aws-sdk-go-v2/service/ssm v1.31.3 h1:U+Zum+CFTxGydzOjfkQiQ3UOdsvMzf+D72/m9W0CvA8=
github.com/aws/aws-sdk-go-v2/service/ssm v1.31.3/go.mod h1:rEsqsZrOp9YvSGPOrcL3pR9+i/QJaWRkAYbuxMa7yCU=
github.com/aws/aws-sdk-go-v2/service/sso v1.11.4 h1:Uw5wBybFQ1UeA9ts0Y07gbv0ncZnIAyw858tDW0NP2o=
github.com/aws/aws-sdk-go-v2/service/sso v1.11.4/go.mod h1:cPDwJwsP4Kff9mldCXAmddjJL6JGQqtA3Mzer2zyr88=
github.com/aws/aws-sdk-go-v2/service/sts v1.16.4 h1:+xtV90n3abQmgzk1pS++FdxZTrPEDgQng6e4/56WR2A=
Expand Down
6 changes: 6 additions & 0 deletions internal/conns/awsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package conns

import (
"fmt"

"github.com/aws/aws-sdk-go-v2/service/ssm"
)

// PartitionHostname returns a hostname with the provider domain suffix for the partition
Expand All @@ -17,3 +19,7 @@ func (client *AWSClient) PartitionHostname(prefix string) string {
func (client *AWSClient) RegionalHostname(prefix string) string {
return fmt.Sprintf("%s.%s.%s", prefix, client.Region, client.DNSSuffix)
}

func (client *AWSClient) SSMClient() *ssm.Client {
return client.ssmClient.Client()
}
3 changes: 3 additions & 0 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions internal/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/route53domains"
"github.com/aws/aws-sdk-go-v2/service/s3control"
"github.com/aws/aws-sdk-go-v2/service/sesv2"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go-v2/service/transcribe"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/endpoints"
Expand Down Expand Up @@ -276,6 +277,14 @@ func (c *Config) ConfigureProvider(ctx context.Context, client *AWSClient) (*AWS
}
})

client.ssmClient.init(&cfg, func() *ssm.Client {
return ssm.NewFromConfig(cfg, func(o *ssm.Options) {
if endpoint := c.Endpoints[names.SSM]; endpoint != "" {
o.EndpointResolver = ssm.EndpointResolverFromURL(endpoint)
}
})
})

// sts
stsConfig := &aws.Config{
Endpoint: aws.String(c.Endpoints[names.STS]),
Expand Down
27 changes: 27 additions & 0 deletions internal/conns/lazy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package conns

import (
"sync"

"github.com/aws/aws-sdk-go-v2/aws"
)

type clientInitFunc[T any] func() T

type lazyClient[T any] struct {
initf clientInitFunc[T]

once sync.Once
client T
}

func (l *lazyClient[T]) init(config *aws.Config, f clientInitFunc[T]) {
l.initf = f
}

func (l *lazyClient[T]) Client() T {
l.once.Do(func() {
l.client = l.initf()
})
return l.client
}
9 changes: 9 additions & 0 deletions internal/create/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func DiagError(service, action, resource, id string, gotError error) diag.Diagno
}
}

func DiagErrorMessage(service, action, resource, id, message string) diag.Diagnostics {
return diag.Diagnostics{
diag.Diagnostic{
Severity: diag.Error,
Summary: ProblemStandardMessage(service, action, resource, id, fmt.Errorf(message)),
},
}
}

// ErrorSetting returns an errors.Error with a standardized error message when setting
// arguments and attributes values.
func SettingError(service, resource, id, argument string, gotError error) error {
Expand Down
3 changes: 3 additions & 0 deletions internal/generate/awsclient/file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
{{ range .Services }}
{{ if ne .GoPackageOverride "" }}{{ .GoPackageOverride }}{{ end -}} "github.com/aws/aws-sdk-go{{ if eq .SDKVersion "2" }}-v2{{ end }}/service/{{ .GoPackage }}"
{{- end }}
ssm_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/hashicorp/terraform-provider-aws/internal/experimental/intf"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand All @@ -25,6 +26,8 @@ type AWSClient struct {
SupportedPlatforms []string
TerraformVersion string

ssmClient lazyClient[*ssm_sdkv2.Client]

{{ range .Services }}
{{ .ProviderNameUpper }}{{ if eq .SDKVersion "1" }}Conn{{ else }}Client{{end}} *{{ if ne .GoPackageOverride "" }}{{ .GoPackageOverride }}{{ else }}{{ .GoPackage }}{{ end }}.{{ .ClientTypeName }}
{{- end }}
Expand Down
3 changes: 1 addition & 2 deletions internal/generate/clientconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ func main() {
}

func writeTemplate(body string, templateName string, td TemplateData) {
// If the file doesn't exist, create it, or append to the file
f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(filename, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("error opening file (%s): %s", filename, err)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/generate/servicesemgrep/configs.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ rules:
patterns:
- pattern-not-regex: "testAcc[a-zA-Z0-9]+Config(_[a-zA-Z0-9_]+_|_)[a-z0-9].*"
- pattern-not: acctest.ConfigCompose(...)
- pattern-not: "..."
severity: WARNING

- id: test-configcompose-funcs-correct-form
languages:
- go
Expand All @@ -40,6 +42,7 @@ rules:
- pattern-not-regex: "testAcc[a-zA-Z0-9]+Config(_[a-zA-Z0-9_]+_|_)[a-z0-9].*"
- pattern-not-regex: "acctest\\..*"
severity: WARNING

- id: test-config-funcs-check
languages:
- go
Expand All @@ -59,6 +62,7 @@ rules:
patterns:
- pattern-regex: "testAccCheck.*"
severity: WARNING

- id: test-configcompose-funcs-check
languages:
- go
Expand Down
4 changes: 4 additions & 0 deletions internal/generate/servicesemgrep/service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
{{- if eq .ServiceAlias "CloudTrail" }}
- pattern-not-regex: ^testAccCloudTrailConfig_.*
{{- end }}
{{- if eq .ServiceAlias "SSM" }}
- pattern-not-regex: ^testAccSSMDefaultPatchBaseline_.+
- pattern-not-regex: ^testAccSSMPatchBaseline_.+
{{- end }}
- pattern-not-regex: ^TestAcc.*
severity: WARNING
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,7 @@ func New(_ context.Context) (*schema.Provider, error) {

"aws_ssm_activation": ssm.ResourceActivation(),
"aws_ssm_association": ssm.ResourceAssociation(),
"aws_ssm_default_patch_baseline": ssm.ResourceDefaultPatchBaseline(),
"aws_ssm_document": ssm.ResourceDocument(),
"aws_ssm_maintenance_window": ssm.ResourceMaintenanceWindow(),
"aws_ssm_maintenance_window_target": ssm.ResourceMaintenanceWindowTarget(),
Expand Down
4 changes: 2 additions & 2 deletions internal/service/apigatewayv2/api_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func testAccAPIMapping_createCertificate(t *testing.T, rName string, certificate
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: nil,
Steps: []resource.TestStep{
{ // nosemgrep:ci.test-config-funcs-correct-form
Config: "# Dummy config.",
{
Config: "# Empty config",
Check: resource.ComposeTestCheckFunc(
testAccCheckAPIMappingCreateCertificate(rName, certificateArn),
),
Expand Down
Loading