Skip to content

Commit

Permalink
r/aws_servicecatalog_principal_portfolio_association: Add StateUpgrad…
Browse files Browse the repository at this point in the history
…ers.
  • Loading branch information
ewbankkit committed Sep 6, 2023
1 parent 704c817 commit 3ea6950
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions internal/service/servicecatalog/principal_portfolio_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func ResourcePrincipalPortfolioAssociation() *schema.Resource {
Delete: schema.DefaultTimeout(3 * time.Minute),
},

SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourcePrincipalPortfolioAssociationV0().CoreConfigSchema().ImpliedType(),
Upgrade: principalPortfolioAssociationUpgradeV0,
Version: 0,
},
},

Schema: map[string]*schema.Schema{
"accept_language": {
Type: schema.TypeString,
Expand Down Expand Up @@ -238,3 +247,47 @@ func FindPrincipalPortfolioAssociation(ctx context.Context, conn *servicecatalog

return findPrincipalForPortfolio(ctx, conn, input, filter)
}

// aws_autoscaling_group aws_servicecatalog_principal_portfolio_association's Schema @v5.15.0 minus validators.
func resourcePrincipalPortfolioAssociationV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"accept_language": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: AcceptLanguageEnglish,
},
"portfolio_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"principal_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"principal_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: servicecatalog.PrincipalTypeIam,
},
},
}
}

func principalPortfolioAssociationUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
if rawState == nil {
rawState = map[string]interface{}{}
}

// Is resource ID in the correct format?
if _, _, _, _, err := PrincipalPortfolioAssociationParseResourceID(rawState["id"].(string)); err != nil {
acceptLanguage, principalARN, portfolioID, principalType := rawState["accept_language"].(string), rawState["principal_arn"].(string), rawState["portfolio_id"].(string), rawState["principal_type"].(string)
rawState["id"] = PrincipalPortfolioAssociationCreateResourceID(acceptLanguage, principalARN, portfolioID, principalType)
}

return rawState, nil
}

0 comments on commit 3ea6950

Please sign in to comment.