Skip to content

Commit

Permalink
extra providerMeta with ElementAs()
Browse files Browse the repository at this point in the history
  • Loading branch information
drewmullen committed Jun 17, 2022
1 parent 2a01ff7 commit 06c5066
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ require (
google.golang.org/grpc v1.46.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)

// replace github.com/hashicorp/aws-sdk-go-base => ../aws-sdk-go-base

replace github.com/hashicorp/aws-sdk-go-base => ../aws-sdk-go-base

// replace github.com/hashicorp/aws-sdk-go-base/v2 => ../aws-sdk-go-base/v2
56 changes: 39 additions & 17 deletions internal/generic/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudcontrol"
cctypes "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/types"
awsbase "github.com/hashicorp/aws-sdk-go-base/v2"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
Expand Down Expand Up @@ -395,36 +396,57 @@ var (
idAttributePath = tftypes.NewAttributePath().WithAttributeName("id")
)

type meta struct {
UserAgents []userAgentProduct `tfsdk:"user_agent"`
type ProviderMetaData struct {
UserAgent types.List `tfsdk:"user_agent"`
}

type userAgentProduct struct {
ProductName types.String `tfsdk:"product_name"`
ProductVersion types.String `tfsdk:"product_version"`
Comment types.String `tfsdk:"comment"`
}
// type meta struct {
// UserAgents []userAgentProduct `tfsdk:"user_agent"`
// }

// type userAgentProduct struct {
// Name types.String `tfsdk:"product_name"`
// Version types.String `tfsdk:"product_version"`
// Comment types.String `tfsdk:"comment"`
// }

func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceRequest, response *tfsdk.CreateResourceResponse) {
ctx = r.cfnTypeContext(ctx)

traceEntry(ctx, "Resource.Create")

var m []meta
providerMeta := request.ProviderMeta
var providerMetaData ProviderMetaData
var userAgentProducts []awsbase.UserAgentProduct

response.Diagnostics.Append(request.ProviderMeta.Get(ctx, &providerMetaData)...)

if response.Diagnostics.HasError() {
return
}

if !providerMetaData.UserAgent.Null && !providerMetaData.UserAgent.Unknown {
response.Diagnostics.Append(providerMetaData.UserAgent.ElementsAs(ctx, &userAgentProducts, false)...)

// diags := providerMeta.GetAttribute(ctx, idAttributePath, &m)
if response.Diagnostics.HasError() {
return
}
}

// var m []meta
// providerMeta := request.ProviderMeta

diags := providerMeta.Get(ctx, &m)

// // diags := providerMeta.GetAttribute(ctx, idAttributePath, &m)

// userAgentProducts
// diags := providerMeta.Get(ctx, &m)

//(*(*r).resourceType).cfTypeName == "AWS::EC2::VPC"
//providerMeta.Raw.value != nil
newCtx := context.WithValue(ctx, "meta", m)
// // userAgentProducts

// //(*(*r).resourceType).cfTypeName == "AWS::EC2::VPC"
// //providerMeta.Raw.value != nil
newCtx := context.WithValue(ctx, "awsbase.ContextScopedUserAgent", userAgentProducts)

conn := r.provider.CloudControlApiClient(newCtx)

// conn := r.provider.CloudControlApiClient(ctx)

tflog.Debug(ctx, "Request.Plan.Raw", map[string]interface{}{
Expand Down Expand Up @@ -506,7 +528,7 @@ func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceReque
}
}

diags = r.populateUnknownValues(ctx, id, &response.State)
diags := r.populateUnknownValues(ctx, id, &response.State)

if diags.HasError() {
response.Diagnostics.Append(diags...)
Expand Down

0 comments on commit 06c5066

Please sign in to comment.