Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/servicecatalog_principal_portfolio_association: New resource #19470

Merged
merged 32 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2099b32
r/servicecat_princ_port_assoc: New resource
YakDriver May 21, 2021
ccfcbf1
tests/r/servicecat_princ_port_assoc: New resource
YakDriver May 21, 2021
1d171d3
docs/r/servicecat_princ_port_assoc: New resource
YakDriver May 21, 2021
e5c04a9
provider: Add new resource
YakDriver May 21, 2021
4832879
r/servicecat: Add finder
YakDriver May 21, 2021
2f05b0b
i/r/servicecat: Add ID funcs for new resource
YakDriver May 21, 2021
d5721e7
i/r/servicecat: Add waiter for new resource
YakDriver May 21, 2021
aa01528
i/servicecat_principal_portfolio_assoc: Remove debug
YakDriver Jun 1, 2021
dbefaed
i/servicecat_princ_port_assoc: Rework not found errors
YakDriver Jun 1, 2021
2873244
i/servicecat_princ_port_assoc: Rework not found errors
YakDriver Jun 1, 2021
02feeca
tests/r/servicecat_prin_port_assoc: Fix tests
YakDriver Jun 1, 2021
67e3664
r/servicecat_prin_port_assoc: Rework not found handling
YakDriver Jun 1, 2021
6fac1a8
r/servicecat_principal_port_assoc: Remove extraneous argument
YakDriver Jun 1, 2021
d61ea81
r/servicecat_principal_port_assoc: Use enum
YakDriver Jun 2, 2021
b1c114b
r/servicecat_prin_port_assoc: Changelog
YakDriver Jun 2, 2021
2f2e905
i/servicecat: Refactor enum
YakDriver Jun 2, 2021
3632d3c
ds/servicecat_constraint: Refactor enum
YakDriver Jun 2, 2021
b3a75ba
r/servicecat_constraint: Refactor enum
YakDriver Jun 2, 2021
862f91c
r/servicecat_service_action: Refactor enum
YakDriver Jun 2, 2021
539b846
tests/r/servicecat_service_action: Refactor enum
YakDriver Jun 2, 2021
872d61a
r/servicecat_provisioning_artifact: Refactor enum
YakDriver Jun 2, 2021
41d6b39
tests/r/servicecat_provisioning_artifact: Refactor enum
YakDriver Jun 2, 2021
feebc1f
tests/r/servicecat_product: Refactor enum
YakDriver Jun 2, 2021
149a1bd
r/servicecat_product: Refactor enum
YakDriver Jun 2, 2021
4815377
tests/r/servicecat_constraint: Refactor enum
YakDriver Jun 2, 2021
d96f180
r/servicecat_portfolio: Refactor enum
YakDriver Jun 2, 2021
1242e3c
r/servicecat_portfolio_share: Refactor enum
YakDriver Jun 2, 2021
a553ae5
tests/r/servicecat_portfolio_share: Refactor enum
YakDriver Jun 2, 2021
b911e58
r/servicecat_prin_port_assoc: Refactor enum
YakDriver Jun 2, 2021
182f4f4
tests/r/servicecat_prin_port_assoc: Refactor enum
YakDriver Jun 2, 2021
400990c
r/servicecat_prod_port_assoc: Refactor enum
YakDriver Jun 2, 2021
3fdc4b7
tests/r/servicecat_prod_port_assoc: Refactor enum
YakDriver Jun 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19470.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_servicecatalog_principal_portfolio_association
```
2 changes: 1 addition & 1 deletion aws/data_source_aws_servicecatalog_constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func dataSourceAwsServiceCatalogConstraint() *schema.Resource {
"accept_language": {
Type: schema.TypeString,
Optional: true,
Default: "en",
Default: tfservicecatalog.AcceptLanguageEnglish,
ValidateFunc: validation.StringInSlice(tfservicecatalog.AcceptLanguage_Values(), false),
},
"description": {
Expand Down
12 changes: 6 additions & 6 deletions aws/internal/service/servicecatalog/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package servicecatalog
const (
// If AWS adds these to the API, we should use those and remove these.

ServiceCatalogAcceptLanguageEnglish = "en"
ServiceCatalogAcceptLanguageJapanese = "jp"
ServiceCatalogAcceptLanguageChinese = "zh"
AcceptLanguageEnglish = "en"
AcceptLanguageJapanese = "jp"
AcceptLanguageChinese = "zh"

ConstraintTypeLaunch = "LAUNCH"
ConstraintTypeNotification = "NOTIFICATION"
Expand All @@ -16,9 +16,9 @@ const (

func AcceptLanguage_Values() []string {
return []string{
ServiceCatalogAcceptLanguageEnglish,
ServiceCatalogAcceptLanguageJapanese,
ServiceCatalogAcceptLanguageChinese,
AcceptLanguageEnglish,
AcceptLanguageJapanese,
AcceptLanguageChinese,
}
}

Expand Down
33 changes: 33 additions & 0 deletions aws/internal/service/servicecatalog/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,36 @@ func TagOptionResourceAssociation(conn *servicecatalog.ServiceCatalog, tagOption

return result, err
}

func PrincipalPortfolioAssociation(conn *servicecatalog.ServiceCatalog, acceptLanguage, principalARN, portfolioID string) (*servicecatalog.Principal, error) {
input := &servicecatalog.ListPrincipalsForPortfolioInput{
PortfolioId: aws.String(portfolioID),
}

if acceptLanguage != "" {
input.AcceptLanguage = aws.String(acceptLanguage)
}

var result *servicecatalog.Principal

err := conn.ListPrincipalsForPortfolioPages(input, func(page *servicecatalog.ListPrincipalsForPortfolioOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, deet := range page.Principals {
if deet == nil {
continue
}

if aws.StringValue(deet.PrincipalARN) == principalARN {
result = deet
return false
}
}

return !lastPage
})

return result, err
}
14 changes: 14 additions & 0 deletions aws/internal/service/servicecatalog/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,17 @@ func ProvisioningArtifactParseID(id string) (string, string, error) {
}
return parts[0], parts[1], nil
}

func PrincipalPortfolioAssociationParseID(id string) (string, string, string, error) {
parts := strings.SplitN(id, ",", 3)

if len(parts) != 3 || parts[0] == "" || parts[1] == "" || parts[2] == "" {
return "", "", "", fmt.Errorf("unexpected format of ID (%s), expected acceptLanguage,principalARN,portfolioID", id)
}

return parts[0], parts[1], parts[2], nil
}

func PrincipalPortfolioAssociationID(acceptLanguage, principalARN, portfolioID string) string {
return strings.Join([]string{acceptLanguage, principalARN, portfolioID}, ",")
}
20 changes: 20 additions & 0 deletions aws/internal/service/servicecatalog/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,23 @@ func ProvisioningArtifactStatus(conn *servicecatalog.ServiceCatalog, id, product
return output, aws.StringValue(output.Status), err
}
}

func PrincipalPortfolioAssociationStatus(conn *servicecatalog.ServiceCatalog, acceptLanguage, principalARN, portfolioID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.PrincipalPortfolioAssociation(conn, acceptLanguage, principalARN, portfolioID)

if tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
return nil, StatusNotFound, err
}

if err != nil {
return nil, servicecatalog.StatusFailed, fmt.Errorf("error describing principal portfolio association: %w", err)
}

if output == nil {
return nil, StatusNotFound, err
}

return output, servicecatalog.StatusAvailable, err
}
}
36 changes: 36 additions & 0 deletions aws/internal/service/servicecatalog/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const (
ProvisioningArtifactReadyTimeout = 3 * time.Minute
ProvisioningArtifactDeletedTimeout = 3 * time.Minute

PrincipalPortfolioAssociationReadyTimeout = 3 * time.Minute
PrincipalPortfolioAssociationDeleteTimeout = 3 * time.Minute

StatusNotFound = "NOT_FOUND"
StatusUnavailable = "UNAVAILABLE"

Expand Down Expand Up @@ -407,3 +410,36 @@ func ProvisioningArtifactDeleted(conn *servicecatalog.ServiceCatalog, id, produc

return nil
}

func PrincipalPortfolioAssociationReady(conn *servicecatalog.ServiceCatalog, acceptLanguage, principalARN, portfolioID string) (*servicecatalog.Principal, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{StatusNotFound, StatusUnavailable},
Target: []string{servicecatalog.StatusAvailable},
Refresh: PrincipalPortfolioAssociationStatus(conn, acceptLanguage, principalARN, portfolioID),
Timeout: PrincipalPortfolioAssociationReadyTimeout,
NotFoundChecks: 5,
MinTimeout: 10 * time.Second,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*servicecatalog.Principal); ok {
return output, err
}

return nil, err
}

func PrincipalPortfolioAssociationDeleted(conn *servicecatalog.ServiceCatalog, acceptLanguage, principalARN, portfolioID string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{servicecatalog.StatusAvailable},
Target: []string{StatusNotFound, StatusUnavailable},
Refresh: PrincipalPortfolioAssociationStatus(conn, acceptLanguage, principalARN, portfolioID),
Timeout: PrincipalPortfolioAssociationDeleteTimeout,
NotFoundChecks: 1,
}

_, err := stateConf.WaitForState()

return err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ func Provider() *schema.Provider {
"aws_servicecatalog_service_action": resourceAwsServiceCatalogServiceAction(),
"aws_servicecatalog_tag_option": resourceAwsServiceCatalogTagOption(),
"aws_servicecatalog_tag_option_resource_association": resourceAwsServiceCatalogTagOptionResourceAssociation(),
"aws_servicecatalog_principal_portfolio_association": resourceAwsServiceCatalogPrincipalPortfolioAssociation(),
"aws_servicecatalog_product_portfolio_association": resourceAwsServiceCatalogProductPortfolioAssociation(),
"aws_servicecatalog_provisioning_artifact": resourceAwsServiceCatalogProvisioningArtifact(),
"aws_service_discovery_http_namespace": resourceAwsServiceDiscoveryHttpNamespace(),
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_servicecatalog_constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func resourceAwsServiceCatalogConstraint() *schema.Resource {
"accept_language": {
Type: schema.TypeString,
Optional: true,
Default: "en",
Default: tfservicecatalog.AcceptLanguageEnglish,
ValidateFunc: validation.StringInSlice(tfservicecatalog.AcceptLanguage_Values(), false),
},
"description": {
Expand Down Expand Up @@ -151,7 +151,7 @@ func resourceAwsServiceCatalogConstraintRead(d *schema.ResourceData, meta interf
acceptLanguage := d.Get("accept_language").(string)

if acceptLanguage == "" {
acceptLanguage = "en"
acceptLanguage = tfservicecatalog.AcceptLanguageEnglish
}

d.Set("accept_language", acceptLanguage)
Expand Down
3 changes: 2 additions & 1 deletion aws/resource_aws_servicecatalog_constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
tfservicecatalog "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/servicecatalog"
)

// add sweeper to delete known test servicecat constraints
Expand Down Expand Up @@ -106,7 +107,7 @@ func TestAccAWSServiceCatalogConstraint_basic(t *testing.T) {
Config: testAccAWSServiceCatalogConstraintConfig_basic(rName, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsServiceCatalogConstraintExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "accept_language", "en"),
resource.TestCheckResourceAttr(resourceName, "accept_language", tfservicecatalog.AcceptLanguageEnglish),
resource.TestCheckResourceAttr(resourceName, "description", rName),
resource.TestCheckResourceAttr(resourceName, "type", "NOTIFICATION"),
resource.TestCheckResourceAttrPair(resourceName, "portfolio_id", "aws_servicecatalog_portfolio.test", "id"),
Expand Down
7 changes: 4 additions & 3 deletions aws/resource_aws_servicecatalog_portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
tfservicecatalog "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/servicecatalog"
)

func resourceAwsServiceCatalogPortfolio() *schema.Resource {
Expand Down Expand Up @@ -68,7 +69,7 @@ func resourceAwsServiceCatalogPortfolioCreate(d *schema.ResourceData, meta inter
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))
input := servicecatalog.CreatePortfolioInput{
AcceptLanguage: aws.String("en"),
AcceptLanguage: aws.String(tfservicecatalog.AcceptLanguageEnglish),
DisplayName: aws.String(d.Get("name").(string)),
IdempotencyToken: aws.String(resource.UniqueId()),
Tags: tags.IgnoreAws().ServicecatalogTags(),
Expand Down Expand Up @@ -98,7 +99,7 @@ func resourceAwsServiceCatalogPortfolioRead(d *schema.ResourceData, meta interfa
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := servicecatalog.DescribePortfolioInput{
AcceptLanguage: aws.String("en"),
AcceptLanguage: aws.String(tfservicecatalog.AcceptLanguageEnglish),
}
input.Id = aws.String(d.Id())

Expand Down Expand Up @@ -138,7 +139,7 @@ func resourceAwsServiceCatalogPortfolioRead(d *schema.ResourceData, meta interfa
func resourceAwsServiceCatalogPortfolioUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).scconn
input := servicecatalog.UpdatePortfolioInput{
AcceptLanguage: aws.String("en"),
AcceptLanguage: aws.String(tfservicecatalog.AcceptLanguageEnglish),
Id: aws.String(d.Id()),
}

Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_servicecatalog_portfolio_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func resourceAwsServiceCatalogPortfolioShare() *schema.Resource {
"accept_language": {
Type: schema.TypeString,
Optional: true,
Default: "en",
Default: tfservicecatalog.AcceptLanguageEnglish,
ValidateFunc: validation.StringInSlice(tfservicecatalog.AcceptLanguage_Values(), false),
},
"accepted": {
Expand Down
5 changes: 3 additions & 2 deletions aws/resource_aws_servicecatalog_portfolio_share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
tfservicecatalog "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/servicecatalog"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/servicecatalog/finder"
)

Expand All @@ -34,7 +35,7 @@ func TestAccAWSServiceCatalogPortfolioShare_basic(t *testing.T) {
Config: testAccAWSServiceCatalogPortfolioShareConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsServiceCatalogPortfolioShareExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "accept_language", "en"),
resource.TestCheckResourceAttr(resourceName, "accept_language", tfservicecatalog.AcceptLanguageEnglish),
resource.TestCheckResourceAttr(resourceName, "accepted", "false"),
resource.TestCheckResourceAttrPair(resourceName, "principal_id", dataSourceName, "account_id"),
resource.TestCheckResourceAttrPair(resourceName, "portfolio_id", compareName, "id"),
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestAccAWSServiceCatalogPortfolioShare_organizationalUnit(t *testing.T) {
Config: testAccAWSServiceCatalogPortfolioShareConfig_organizationalUnit(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsServiceCatalogPortfolioShareExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "accept_language", "en"),
resource.TestCheckResourceAttr(resourceName, "accept_language", tfservicecatalog.AcceptLanguageEnglish),
resource.TestCheckResourceAttr(resourceName, "accepted", "true"),
resource.TestCheckResourceAttrPair(resourceName, "principal_id", "aws_organizations_organizational_unit.test", "id"),
resource.TestCheckResourceAttrPair(resourceName, "portfolio_id", compareName, "id"),
Expand Down
Loading