From 3ea695060a7c9dd32ecd1d66f6f2d15e6e1ff2c3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 6 Sep 2023 15:40:47 -0400 Subject: [PATCH] r/aws_servicecatalog_principal_portfolio_association: Add StateUpgraders. --- .../principal_portfolio_association.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/internal/service/servicecatalog/principal_portfolio_association.go b/internal/service/servicecatalog/principal_portfolio_association.go index b5e130ff650..fae6b29fe54 100644 --- a/internal/service/servicecatalog/principal_portfolio_association.go +++ b/internal/service/servicecatalog/principal_portfolio_association.go @@ -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, @@ -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 +}