-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Service Catalog Provisioned Product and related resources #13797
Closed
ahgittin
wants to merge
168
commits into
hashicorp:main
from
cloudsoft:f-servicecatalog-provisioned-product-and-friends
Closed
Changes from all commits
Commits
Show all changes
168 commits
Select commit
Hold shift + click to select a range
f6321f3
refactoring artifact definition
bw-intuit 8915edc
wip adding artifact block
bw-intuit f365893
refactoring to support new format
bw-intuit bfa2bc2
minor code cleanup
bw-intuit 9227706
update based on code review
bw-intuit 9370c2d
updates based on code review
bw-intuit 0e57346
refactoring to updated template structure
bw-intuit 07107de
fix test
bw-intuit ea45424
minor code / test cleanup
bw-intuit 051a1a0
adding comment
bw-intuit 5179004
reading template url, fix import
bw-intuit 88f81f0
refactored, added acceptance tests and documentation
trung 22148da
minor fixes
trung 8870e42
initial testing
e887f5f
hope and prayer
b261bbd
found the work of @trung and getting it up and running
c01782c
intial creation working
bea44a7
updates
383dbfd
Merge remote-tracking branch 'trung/f-service-catalog' into sc-produc…
ahgittin 975fd2d
Merge remote-tracking branch 'frc9/master' into sc-product-and-pp
ahgittin 848689c
Merge branch 'master' into sc-product-and-pp
ahgittin 413cd8a
update servicecatalog_product helper imports
kemitix dee8315
revert go.mod and go.sum
ahgittin 56493a6
fix error handling on PP
ahgittin 1d8c7a6
fix syntax errors in servicecatalog product tests
ahgittin bfaadb1
include TODO items for things not supported on product
ahgittin 243dc9a
provisioned product - create, read, and delete minimally working
ahgittin 440ef4b
Merge branch 'master' into sc-product-and-pp
kemitix 676b9d0
sc-product: define timeouts for update and delete operations
kemitix eb1a397
sc-product: generate idempotencyToken as resource id
kemitix 258271d
sc-product: extract waitFor…Status method
kemitix 93fbd22
sc-provisioned-product: add wait for resource to create
kemitix 24f04a2
Merge remote-tracking branch 'origin/master' into sc-product-and-pp
ahgittin 1818eac
minor corrections to product doc, and add a useful "complete" example
ahgittin 3b98f38
Merge branch 'sc-product-and-pp' of github.com:cloudsoft/terraform-pr…
ahgittin 63763ef
sc-product-portfolio-assoc: crud
kemitix 7a15c8c
add docs for service catalog provisioned product and portfolio-produc…
ahgittin 222fea6
Merge branch 'sc-product-and-pp' of github.com:cloudsoft/terraform-pr…
ahgittin 971ac5b
sc-product-portfolio-assoc: cast ids to string early
kemitix edc5efd
sc-product-portfolio-assoc: fetch all pages ListPortfoliosForProduct
kemitix b24619a
sc-product-portfolio-assoc: rename methods to fit existing pattern
kemitix 25ab24a
update PP and add'l fields
ahgittin 07c104a
Merge branch 'sc-product-and-pp' of github.com:cloudsoft/terraform-pr…
ahgittin 610384d
SC PP - support params, tags; better wait logic
ahgittin 4e025ed
SC - Product - wait for completion of tasks, not just submission
ahgittin 3c661c6
sc-product-portfolio-assoc: register in provider.go
kemitix 1b8d9f3
sc-product-portfolio-assoc: first pass at basic test
kemitix e1327f5
wait for, and test, deletion of SC Product and SC ProvisionedProduct
ahgittin 515b1cd
Merge branch 'sc-product-and-pp' of github.com:cloudsoft/terraform-pr…
ahgittin 0b7e87e
sc-product-portfolio-assoc: minor updates to docs
kemitix 7377257
fix ID syntax for portfolio-product-association -- all tests passing,…
ahgittin c94fab4
sc-product-portfolio-assoc: revert to standard format for arguments
kemitix 035dfac
Merge branch 'sc-product-and-pp' of github.com:cloudsoft/terraform-pr…
ahgittin 59fa151
sc-provisioned-product: fix typo in docs
kemitix c34bb97
add portfolio-principal association, and use it for product provision…
ahgittin d22fcd8
Merge branch 'sc-product-and-pp' of github.com:cloudsoft/terraform-pr…
ahgittin 888aa0b
sc-portfolio-assocs: Add todo notes to reduce api calls
kemitix 06af8fb
sc-portfolio-assocs: only fetch pages when assoc not yet found
kemitix 9294fb1
fix the product provisioning test, ensure use of separate providers a…
ahgittin 80ff8af
Merge branch 'sc-product-and-pp' of github.com:cloudsoft/terraform-pr…
ahgittin f096f5d
Merge branch 'master' into sc-product-and-pp
ahgittin f5ca63e
SC provisioned-product test passing!
ahgittin ae3e74d
tidy up - merge util class with the (only) place it is used
ahgittin bc84989
apply gofmt
ahgittin 9793677
SC - more miny tidies and explanations
ahgittin b8b8b4b
shorten prefixes to fit within 20 char limit
ahgittin 866f047
fix most linter-flagged issues
ahgittin 19fca67
address go lint issues
ahgittin 603d288
address linter issues in docs page (deprecated frontmatter)
ahgittin eee00a1
SC - address first round of PR review comments
ahgittin 08716d3
revert the index files - not to have any SC items (to avoid merge con…
ahgittin 70ac64a
remove provisioned product additions for now, focus on incremental PRs
ahgittin 625c9b7
remove portfolio-principal-association additions for now, focus on in…
ahgittin 2dcb083
remove portfolio-product-association additions for now, focus on incr…
ahgittin 85d33e4
remove product additions and portfolio changes for now, focus on incr…
ahgittin 9af48f5
restore product additions and portfolio changes, focus on incremental…
ahgittin db3e1aa
improve product tests to conform with conventions
ahgittin 8cfecab
restore portfolio-principal-association additions for now, focus on i…
ahgittin 038fd4a
restore portfolio-product-association additions for now, focus on inc…
ahgittin 0551515
add product to index files
ahgittin 46303a4
add portfolio-principal association to index files
ahgittin 6983acb
Merge branch 'f-servicecatalog-product' into f-servicecatalog-portfol…
ahgittin c655600
add portfolio-product association to index files
ahgittin 3994bf4
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin dfbc50f
Revert "remove provisioned product additions for now, focus on increm…
ahgittin 9cea7db
add provisioned product to index files
ahgittin bdce9ea
add checks on AWS output - name and whether product has been re-creat…
ahgittin a57bf3f
test improvements - add disappears test, simplify template
ahgittin 256bd32
correct ID format in docs
ahgittin a7f6049
add and update all tests, all passing
ahgittin 08a888d
Merge branch 'f-servicecatalog-product' into f-servicecatalog-portfol…
ahgittin ccba736
Fix two linter problems
ahgittin 822ac3f
remove "update" (all replaces), backfill additional tests, all passing
ahgittin c5870a1
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin 763f582
Merge branch 'f-servicecatalog-portfolio-product-association' into f-…
ahgittin 4724b3e
update product_test method names to match prevailing conventions
ahgittin 11d3c81
update portfolio_principal_association_test method names to match pre…
ahgittin 7dddfab
update portfolio_product_association_test method names to match preva…
ahgittin 9ac47f6
Merge branch 'f-servicecatalog-product' into f-servicecatalog-portfol…
ahgittin 9a2da04
Merge branch 'f-servicecatalog-product' into f-servicecatalog-provisi…
ahgittin 7c4981c
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin cd321eb
Merge branch 'f-servicecatalog-portfolio-product-association' into f-…
ahgittin 98c2c44
SC product - fix bug in tag removal
ahgittin 242ee56
Merge branch 'f-servicecatalog-product' into f-servicecatalog-portfol…
ahgittin ecb78d4
Merge branch 'f-servicecatalog-portfolio-product-association' into f-…
ahgittin 90a0a2c
update portfolio_test method names to match prevailing conventions
ahgittin c22f20e
Merge branch 'td-servicecatalog-portfolio' into f-servicecatalog-prov…
ahgittin ee6d2cf
update SC provisioned_product_test
ahgittin 9ba34d8
remove changes to Portfolio here; do them in another PR
ahgittin 4320102
rearrange imports to match convention
ahgittin 5717d01
add note on using the SC portfolio to the docs
ahgittin 4cee871
Merge branch 'f-servicecatalog-product' into f-servicecatalog-portfol…
ahgittin 0c70f23
Merge branch 'f-servicecatalog-product' into f-servicecatalog-provisi…
ahgittin 26e4e36
Merge branch 'f-servicecatalog-portfolio-product-association' into f-…
ahgittin 0158cd0
Merge branch 'td-servicecatalog-portfolio' into f-servicecatalog-prov…
ahgittin c8c96cd
add new fields, get tests working
ahgittin a2da3ee
SC provisioned product - change params and outputs to map, add test f…
ahgittin 0eb761d
replace deprecated `"${x}"` expressions with just `x`
ahgittin d37ad72
Merge branch 'f-servicecatalog-product' into f-servicecatalog-provisi…
ahgittin 05c6044
SC product - use standard method for SC tags from input
ahgittin 39a5a7a
SC product - remove pointless extra conversion of map from SC tags
ahgittin 2ed98dc
SC product - code review - refactor extracting methods and add valida…
ahgittin 24cb977
SC Product - change tests to be very very much like the recommended f…
ahgittin 81ba7eb
Merge branch 'f-servicecatalog-product' into f-servicecatalog-provisi…
ahgittin 131d9ed
Merge branch 'master' into f-servicecatalog-product
ahgittin a0da08f
conform markdown examples to new terrafmt
ahgittin 312d002
Merge branch 'f-servicecatalog-product' into f-servicecatalog-provisi…
ahgittin 862fb04
SC Product - remove region on bucket, it no longer works
ahgittin 40a91d1
SC Portfolio Principal Association - tests updated
ahgittin 87e6ab0
SC Portfolio Principal Association - conform markdown examples to ter…
ahgittin fd79364
Merge branch 'master' into f-servicecatalog-portfolio-principal-assoc…
ahgittin f5076f3
Merge branch 'f-servicecatalog-product' into f-servicecatalog-portfol…
ahgittin aa3a333
SC Portfolio Product Association - conform markdown examples to terra…
ahgittin 3214eac
SC Portfolio Product Association - tests updated
ahgittin a8576b5
Merge branch 'master' into td-servicecatalog-portfolio
ahgittin d41a8c6
SC Portfolio - update tests, esp disappears test
ahgittin 978af98
Merge branch 'f-servicecatalog-portfolio-product-association' into f-…
ahgittin b03c4c4
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin 2f7c275
Merge branch 'td-servicecatalog-portfolio' into f-servicecatalog-prov…
ahgittin c69e597
SC PP - conform markdown examples to terrafmt requirements
ahgittin 2192e12
SC Provisioned Product - update tests
ahgittin f1b3c20
SC Portfolio Principal Association - test for principal existence
ahgittin eecd2fd
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin be3065b
SC Portfolio Principal Association - format tidy
ahgittin e1d1d3b
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin 1294114
SC Portfolio Principal Association - fix principal check
ahgittin 1e57005
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin da120b2
Merge branch 'master' into f-servicecatalog-product
ahgittin 2d6833b
Update imports to use v2/ of plugin SDK
ahgittin ec3aaed
Merge branch 'f-servicecatalog-product' into f-servicecatalog-portfol…
ahgittin 597a929
Update imports to use v2/ of plugin SDK
ahgittin 33be215
Merge branch 'master' into f-servicecatalog-portfolio-principal-assoc…
ahgittin c8bae8b
Update imports to use v2/ of plugin SDK
ahgittin 8c4f3bb
Merge branch 'master' into td-servicecatalog-portfolio
ahgittin a6ec0ca
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin 2703aa7
Merge branch 'f-servicecatalog-portfolio-product-association' into f-…
ahgittin d90c3f1
Merge branch 'td-servicecatalog-portfolio' into f-servicecatalog-prov…
ahgittin ef4b2d1
Update imports to use v2/ of plugin SDK
ahgittin 9c9dd75
fix trailing spaces in markdown
ahgittin 08e3b91
fix trailing spaces in markdown
ahgittin e65df4f
fix markdown indentation
ahgittin 7dbf42f
Merge branch 'f-servicecatalog-product' into f-servicecatalog-portfol…
ahgittin 5eef5df
fix trailing spaces in markdown
ahgittin 9e7e621
Merge branch 'f-servicecatalog-portfolio-product-association' into f-…
ahgittin 0818862
Merge branch 'f-servicecatalog-portfolio-principal-association' into …
ahgittin fc440d5
fix markdown trailing space
ahgittin a61501d
fix markdown trailing spaces
ahgittin 9da757f
Merge branch 'td-servicecatalog-portfolio' into f-servicecatalog-prov…
ahgittin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
aws/resource_aws_servicecatalog_portfolio_principal_association.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/servicecatalog" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceAwsServiceCatalogPortfolioPrincipalAssociation() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsServiceCatalogPortfolioPrincipalAssociationCreate, | ||
Read: resourceAwsServiceCatalogPortfolioPrincipalAssociationRead, | ||
Delete: resourceAwsServiceCatalogPortfolioPrincipalAssociationDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(10 * time.Minute), | ||
Delete: schema.DefaultTimeout(10 * time.Minute), | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"portfolio_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"principal_arn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validateArn, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsServiceCatalogPortfolioPrincipalAssociationCreate(d *schema.ResourceData, meta interface{}) error { | ||
_, portfolioId, principalArn, err := resourceAwsServiceCatalogPortfolioPrincipalAssociationRequiredParameters(d) | ||
if err != nil { | ||
return err | ||
} | ||
input := servicecatalog.AssociatePrincipalWithPortfolioInput{ | ||
PortfolioId: aws.String(portfolioId), | ||
PrincipalARN: aws.String(principalArn), | ||
PrincipalType: aws.String(servicecatalog.PrincipalTypeIam), | ||
} | ||
conn := meta.(*AWSClient).scconn | ||
_, err = conn.AssociatePrincipalWithPortfolio(&input) | ||
if err != nil { | ||
return fmt.Errorf("creating Service Catalog Principal(%s)/Portfolio(%s) Association failed: %s", | ||
principalArn, portfolioId, err.Error()) | ||
} | ||
|
||
result := resourceAwsServiceCatalogPortfolioPrincipalAssociationRead(d, meta) | ||
// even after one successful read, the eventual consistency can regress, so delay a bit more before | ||
// reporting this as created to prevent dependencies (eg products being provisioned) running too early | ||
time.Sleep(time.Second * 5) | ||
return result | ||
} | ||
|
||
func resourceAwsServiceCatalogPortfolioPrincipalAssociationRead(d *schema.ResourceData, meta interface{}) error { | ||
id, portfolioId, principalArn, err := resourceAwsServiceCatalogPortfolioPrincipalAssociationRequiredParameters(d) | ||
if err != nil { | ||
return err | ||
} | ||
input := servicecatalog.ListPrincipalsForPortfolioInput{ | ||
PortfolioId: aws.String(portfolioId), | ||
} | ||
conn := meta.(*AWSClient).scconn | ||
isFound := false | ||
|
||
// listing principals for portfolio is a paginated operation | ||
// and if a principal has recently been added, it can contain the ID while it is stabilising, | ||
// so we retry for up to 1 minute if it is stabilising and the ARN we are looking for is not found | ||
err = resource.Retry(1*time.Minute, func() *resource.RetryError { | ||
var pageToken = "" | ||
for { | ||
nonArnFound := false | ||
pageOfDetails, nextPageToken, err := resourceAwsServiceCatalogPortfolioPrincipalAssociationListPrincipalsForPortfolioPage(conn, input, &pageToken) | ||
if err != nil { | ||
return resource.NonRetryableError(err) | ||
} | ||
for _, principal := range pageOfDetails { | ||
if aws.StringValue(principal.PrincipalARN) == principalArn { | ||
isFound = true | ||
return nil | ||
} | ||
if !strings.HasPrefix(aws.StringValue(principal.PrincipalARN), "arn:") { | ||
nonArnFound = true | ||
} | ||
} | ||
if nextPageToken == nil { | ||
if nonArnFound { | ||
log.Printf("[DEBUG] Service Catalog Principal(%s)/Portfolio(%s) Association not found, but principals detected as stabilizing", | ||
principalArn, portfolioId) | ||
return resource.RetryableError(fmt.Errorf("Principals stabilizing")) | ||
} else { | ||
return nil | ||
} | ||
} | ||
pageToken = aws.StringValue(nextPageToken) | ||
} | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
if isFound { | ||
d.SetId(id) | ||
} else { | ||
log.Printf("[WARN] Service Catalog Principal(%s)/Portfolio(%s) Association not found, removing from state", | ||
principalArn, portfolioId) | ||
d.SetId("") | ||
} | ||
d.Set("principal_arn", principalArn) | ||
d.Set("portfolio_id", portfolioId) | ||
return nil | ||
} | ||
|
||
func resourceAwsServiceCatalogPortfolioPrincipalAssociationListPrincipalsForPortfolioPage(conn *servicecatalog.ServiceCatalog, input servicecatalog.ListPrincipalsForPortfolioInput, nextPageToken *string) ([]*servicecatalog.Principal, *string, error) { | ||
input.PageToken = nextPageToken | ||
var page, err = conn.ListPrincipalsForPortfolio(&input) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("retrieving Service Catalog Associations for Principal/Portfolios: %s", err.Error()) | ||
} | ||
principalDetails := page.Principals | ||
return principalDetails, page.NextPageToken, nil | ||
} | ||
|
||
func resourceAwsServiceCatalogPortfolioPrincipalAssociationDelete(d *schema.ResourceData, meta interface{}) error { | ||
_, portfolioId, principalArn, err := resourceAwsServiceCatalogPortfolioPrincipalAssociationRequiredParameters(d) | ||
if err != nil { | ||
return err | ||
} | ||
input := servicecatalog.DisassociatePrincipalFromPortfolioInput{ | ||
PortfolioId: aws.String(portfolioId), | ||
PrincipalARN: aws.String(principalArn), | ||
} | ||
conn := meta.(*AWSClient).scconn | ||
_, err = conn.DisassociatePrincipalFromPortfolio(&input) | ||
if err != nil { | ||
return fmt.Errorf("deleting Service Catalog Principal(%s)/Portfolio(%s) Association failed: %s", | ||
principalArn, portfolioId, err.Error()) | ||
} | ||
return nil | ||
} | ||
|
||
func resourceAwsServiceCatalogPortfolioPrincipalAssociationRequiredParameters(d *schema.ResourceData) (string, string, string, error) { | ||
// ":" recommended as separator where multiple fields needed to uniquely identify and import, based on https://www.terraform.io/docs/extend/resources/import.html#importer-state-function | ||
// (as in this case where AWS doesn't treat this association as a first class resource; it has no AWS identifier) | ||
// this is not a valid "identifier" character according to https://www.terraform.io/docs/configuration/syntax.html#identifiers | ||
// but that does not seem to apply to this internal "id" | ||
principalArn, ok := d.GetOk("principal_arn") | ||
portfolioId, ok2 := d.GetOk("portfolio_id") | ||
if ok && ok2 { | ||
id := portfolioId.(string) + ":" + principalArn.(string) | ||
return id, portfolioId.(string), principalArn.(string), nil | ||
} else if ok || ok2 { | ||
return "", "", "", fmt.Errorf("Invalid state - principal_arn and portfolio_id must both be set or neither set to infer from ID") | ||
} else if d.Id() != "" { | ||
return parseServiceCatalogPortfolioPrincipalAssociationResourceId(d.Id()) | ||
} else { | ||
return "", "", "", fmt.Errorf("Invalid state - principal_arn and portfolio_id must be set, or ID set to import") | ||
} | ||
} | ||
|
||
func parseServiceCatalogPortfolioPrincipalAssociationResourceId(id string) (string, string, string, error) { | ||
s := strings.SplitN(id, ":", 2) | ||
if len(s) != 2 { | ||
return "", "", "", fmt.Errorf("Invalid ID '%s' - should be of format <portfolio_id>:<principal-arn>", id) | ||
} | ||
return id, s[0], s[1], nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit, can you split the deps to go packages and external dep packages like other resources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - all files (check-in to come)