Skip to content

Commit

Permalink
Automatically detect sharing instances
Browse files Browse the repository at this point in the history
  • Loading branch information
t0yv0 committed Sep 13, 2024
1 parent 244c1b6 commit 28a3e58
Show file tree
Hide file tree
Showing 21 changed files with 69,761 additions and 1,651 deletions.
1 change: 1 addition & 0 deletions provider/pkg/quicksight/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shared-types-detected.json
125 changes: 7 additions & 118 deletions provider/pkg/quicksight/quicksight.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package quicksight

import (
"fmt"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

const (
Expand All @@ -17,7 +15,6 @@ func ConfigureQuicksight(
awsResource func(mod string, name string) tokens.Type,
awsDataSource func(mod string, name string) tokens.ModuleMember,
) {
st := &state{defined: map[tokens.Type]struct{}{}}
quickSightResources := map[string]*info.Resource{
"aws_quicksight_account_subscription": {Tok: awsResource(quicksightMod, "AccountSubscription")},
"aws_quicksight_data_set": {Tok: awsResource(quicksightMod, "DataSet")},
Expand All @@ -26,9 +23,9 @@ func ConfigureQuicksight(
"aws_quicksight_group_membership": {Tok: awsResource(quicksightMod, "GroupMembership")},
"aws_quicksight_data_source": {Tok: awsResource(quicksightMod, "DataSource")},
"aws_quicksight_folder": {Tok: awsResource(quicksightMod, "Folder")},
"aws_quicksight_template": resourceTemplate(st, awsResource(quicksightMod, "Template")),
"aws_quicksight_analysis": resourceAnalysis(st, awsResource(quicksightMod, "Analysis")),
"aws_quicksight_dashboard": resourceDashboard(st, awsResource(quicksightMod, "Dashboard")),
"aws_quicksight_template": {Tok: awsResource(quicksightMod, "Template")},
"aws_quicksight_analysis": {Tok: awsResource(quicksightMod, "Analysis")},
"aws_quicksight_dashboard": {Tok: awsResource(quicksightMod, "Dashboard")},
}

for k, v := range quickSightResources {
Expand All @@ -44,117 +41,9 @@ func ConfigureQuicksight(
for k, v := range quickSightDataSources {
providerInfo.DataSources[k] = v
}
}

func resourceAnalysis(st *state, token tokens.Type) *info.Resource {
columnConfigs := &info.Schema{
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"format_configuration": formatConfigurationSchema(st),
},
},
}
return &info.Resource{
Tok: token,
Fields: map[string]*info.Schema{
"definition": {
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"analysis_defaults": analysisDefaultSchema(st),
"column_configurations": columnConfigs,
"sheets": {
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"visuals": visualsSchema(st),
},
},
},
},
},
},
},
}
}

func resourceDashboard(st *state, token tokens.Type) *info.Resource {
columnConfigs := &info.Schema{
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"format_configuration": formatConfigurationSchema(st),
},
},
}
return &info.Resource{
Tok: token,
Fields: map[string]*info.Schema{
"definition": {
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"analysis_defaults": analysisDefaultSchema(st),
"column_configurations": columnConfigs,
"sheets": {
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"visuals": visualsSchema(st),
},
},
},
},
},
},
},
}
}
st, err := readSharedTypesFile("provider/pkg/quicksight/shared-types-rewrites.json")
contract.AssertNoErrorf(err, "failed to read shared-types-rewrites.json")

func resourceTemplate(st *state, token tokens.Type) *info.Resource {
columnConfigs := &info.Schema{
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"format_configuration": formatConfigurationSchema(st),
},
},
}
return &info.Resource{
Tok: token,
Fields: map[string]*info.Schema{
"definition": {
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"analysis_defaults": analysisDefaultSchema(st),
"column_configurations": columnConfigs,
"sheets": {
Elem: &info.Schema{
Fields: map[string]*info.Schema{
"visuals": visualsSchema(st),
},
},
},
},
},
},
},
}
}

type state struct {
defined map[tokens.Type]struct{}
}

func (st *state) define(name string, schema *info.Schema) *info.Schema {
tok := tokens.Type(fmt.Sprintf("aws:quicksight/%s:%s", name, name))
copy := *schema
if schema.Elem == nil {
copy.Elem = &info.Schema{}
} else {
elem := *schema.Elem
copy.Elem = &elem
}
if _, ok := st.defined[tok]; !ok {
st.defined[tok] = struct{}{}
copy.Elem.TypeName = tfbridge.Ref(name)
return &copy
}
copy.Elem.Type = tok
copy.Elem.OmitType = true
return &copy
shareTypes(st, providerInfo)
}
Loading

0 comments on commit 28a3e58

Please sign in to comment.