-
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 #40313 from bschaatsbergen/f/ephemeral-ssm-parameter
ssm: add ephemeral `aws_ssm_parameter`
- Loading branch information
Showing
5 changed files
with
483 additions
and
0 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:new-ephemeral | ||
aws_ssm_parameter | ||
``` |
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,107 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package ssm | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/ephemeral" | ||
"github.com/hashicorp/terraform-plugin-framework/ephemeral/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-provider-aws/internal/create" | ||
"github.com/hashicorp/terraform-provider-aws/internal/framework" | ||
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" | ||
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
const ( | ||
ERNameParameter = "Ephemeral Resource Parameter" | ||
) | ||
|
||
// @EphemeralResource(aws_ssm_parameter, name="Parameter") | ||
func newEphemeralParameter(_ context.Context) (ephemeral.EphemeralResourceWithConfigure, error) { | ||
return &ephemeralParameter{}, nil | ||
} | ||
|
||
type ephemeralParameter struct { | ||
framework.EphemeralResourceWithConfigure | ||
} | ||
|
||
func (e *ephemeralParameter) Metadata(_ context.Context, _ ephemeral.MetadataRequest, response *ephemeral.MetadataResponse) { | ||
response.TypeName = "aws_ssm_parameter" | ||
} | ||
|
||
func (e *ephemeralParameter) Schema(ctx context.Context, _ ephemeral.SchemaRequest, response *ephemeral.SchemaResponse) { | ||
response.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
names.AttrARN: schema.StringAttribute{ | ||
CustomType: fwtypes.ARNType, | ||
Required: true, | ||
}, | ||
names.AttrName: schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
names.AttrType: schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
names.AttrValue: schema.StringAttribute{ | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
names.AttrVersion: schema.Int64Attribute{ | ||
Computed: true, | ||
}, | ||
"with_decryption": schema.BoolAttribute{ | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (e *ephemeralParameter) Open(ctx context.Context, request ephemeral.OpenRequest, response *ephemeral.OpenResponse) { | ||
var data epParameterData | ||
conn := e.Meta().SSMClient(ctx) | ||
|
||
response.Diagnostics.Append(request.Config.Get(ctx, &data)...) | ||
if response.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
// Terraform does not have the notion of planning for ephemeral resources, | ||
// data sources, or providers. As a result, default handlers are not | ||
// implemented for these objects in the Terraform Plugin Framework. | ||
// | ||
// To align with the data source data.aws_ssm_parameter, | ||
// we default `with_decryption`. | ||
if data.WithDecryption.IsNull() { | ||
data.WithDecryption = types.BoolValue(true) | ||
} | ||
|
||
output, err := findParameterByName(ctx, conn, data.ARN.ValueString(), data.WithDecryption.ValueBool()) | ||
if err != nil { | ||
response.Diagnostics.AddError( | ||
create.ProblemStandardMessage(names.SSM, create.ErrActionReading, ERNameParameter, data.ARN.String(), err), | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data)...) | ||
if response.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
response.Diagnostics.Append(response.Result.Set(ctx, &data)...) | ||
} | ||
|
||
type epParameterData struct { | ||
ARN fwtypes.ARN `tfsdk:"arn"` | ||
Name types.String `tfsdk:"name"` | ||
Type types.String `tfsdk:"type"` | ||
Value types.String `tfsdk:"value"` | ||
Version types.Int64 `tfsdk:"version"` | ||
WithDecryption types.Bool `tfsdk:"with_decryption"` | ||
} |
Oops, something went wrong.