Skip to content

Commit 9a5e9a5

Browse files
Terraform Team AutomationMaxrovr
authored andcommitted
Bug fix - Update marketplace documentation and make a resource discoverable
1 parent c7cd751 commit 9a5e9a5

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

internal/integrationtest/marketplace_accepted_agreement_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func TestMarketplaceAcceptedAgreementResource_basic(t *testing.T) {
152152
},
153153
),
154154
},
155+
155156
// verify datasource
156157
{
157158
Config: config +

internal/integrationtest/marketplace_publication_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func TestMarketplacePublicationResource_basic(t *testing.T) {
137137
{
138138
Config: config + compartmentIdVariableStr + MarketplacePublicationResourceDependencies,
139139
},
140+
140141
// verify Create with optionals
141142
{
142143
Config: config + compartmentIdVariableStr + MarketplacePublicationResourceDependencies +

internal/service/marketplace/marketplace_export.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package marketplace
22

33
import (
4-
oci_marketplace "github.com/oracle/oci-go-sdk/v65/marketplace"
4+
"context"
5+
"fmt"
56

7+
oci_marketplace "github.com/oracle/oci-go-sdk/v65/marketplace"
68
tf_export "github.com/oracle/terraform-provider-oci/internal/commonexport"
9+
"github.com/oracle/terraform-provider-oci/internal/tfresource"
710
)
811

912
func init() {
13+
exportMarketplacePublicationHints.FindResourcesOverrideFn = findPublications
1014
tf_export.RegisterCompartmentGraphs("marketplace", marketplaceResourceGraph)
1115
}
1216

@@ -28,12 +32,72 @@ var exportMarketplacePublicationHints = &tf_export.TerraformResourceHints{
2832
ResourceAbbreviation: "publication",
2933
RequireResourceRefresh: true,
3034
DiscoverableLifecycleStates: []string{
35+
string(oci_marketplace.PublicationLifecycleStateCreating),
3136
string(oci_marketplace.PublicationLifecycleStateActive),
3237
},
3338
}
3439

3540
var marketplaceResourceGraph = tf_export.TerraformResourceGraph{
3641
"oci_identity_compartment": {
3742
{TerraformResourceHints: exportMarketplaceAcceptedAgreementHints},
43+
{TerraformResourceHints: exportMarketplacePublicationHints},
3844
},
3945
}
46+
47+
func findPublications(ctx *tf_export.ResourceDiscoveryContext, tfMeta *tf_export.TerraformResourceAssociation, parent *tf_export.OCIResource, resourceGraph *tf_export.TerraformResourceGraph) (resources []*tf_export.OCIResource, err error) {
48+
results := []*tf_export.OCIResource{}
49+
request := oci_marketplace.ListPublicationsRequest{}
50+
request.ListingType = oci_marketplace.ListPublicationsListingTypeCommunity
51+
request.CompartmentId = &parent.CompartmentId
52+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(true, "marketplace")
53+
54+
response, err := ctx.Clients.MarketplaceClient().ListPublications(context.Background(), request)
55+
if err != nil {
56+
return nil, err
57+
}
58+
59+
request.Page = response.OpcNextPage
60+
61+
for request.Page != nil {
62+
listResponse, err := ctx.Clients.MarketplaceClient().ListPublications(context.Background(), request)
63+
if err != nil {
64+
return nil, err
65+
}
66+
response.Items = append(response.Items, listResponse.Items...)
67+
request.Page = listResponse.OpcNextPage
68+
}
69+
70+
for _, publication := range response.Items {
71+
publicationResource := tf_export.ResourcesMap[tfMeta.ResourceClass]
72+
73+
d := publicationResource.TestResourceData()
74+
d.SetId(*publication.Id)
75+
76+
if err := publicationResource.Read(d, ctx.Clients); err != nil {
77+
rdError := &tf_export.ResourceDiscoveryError{ResourceType: tfMeta.ResourceClass, ParentResource: parent.TerraformName, Error: err, ResourceGraph: resourceGraph}
78+
ctx.AddErrorToList(rdError)
79+
continue
80+
}
81+
82+
resource := &tf_export.OCIResource{
83+
CompartmentId: parent.CompartmentId,
84+
SourceAttributes: tf_export.ConvertResourceDataToMap(publicationResource.Schema, d),
85+
RawResource: publication,
86+
TerraformResource: tf_export.TerraformResource{
87+
Id: d.Id(),
88+
TerraformClass: tfMeta.ResourceClass,
89+
},
90+
GetHclStringFn: tf_export.GetHclStringFromGenericMap,
91+
Parent: parent,
92+
}
93+
94+
if resource.TerraformName, err = tf_export.GenerateTerraformNameFromResource(resource.SourceAttributes, publicationResource.Schema); err != nil {
95+
resource.TerraformName = fmt.Sprintf("%s_%s", parent.Parent.TerraformName, *publication.Name)
96+
resource.TerraformName = tf_export.CheckDuplicateResourceName(resource.TerraformName)
97+
}
98+
99+
results = append(results, resource)
100+
}
101+
102+
return results, nil
103+
}

website/docs/d/marketplace_listing.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ data "oci_marketplace_listing" "test_listing" {
4343

4444
The following arguments are supported:
4545

46-
* `compartment_id` - (Optional) The unique identifier for the compartment.
46+
* `compartment_id` - (Optional) The unique identifier for the compartment. It is mandatory when used in non-commercial realms.
4747
* `listing_id` - (Required) The unique identifier for the listing.
4848

4949

website/docs/d/marketplace_listings.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ data "oci_marketplace_listings" "test_listings" {
5252
The following arguments are supported:
5353

5454
* `category` - (Optional) Name of the product category or categories. If you specify multiple categories, then Marketplace returns any listing with one or more matching categories.
55-
* `compartment_id` - (Optional) The unique identifier for the compartment.
55+
* `compartment_id` - (Optional) The unique identifier for the compartment. It is mandatory when used in non-commercial realms.
5656
* `image_id` - (Optional) The image identifier of the listing.
5757
* `is_featured` - (Optional) Indicates whether to show only featured listings. If this is set to `false` or is omitted, then all listings will be returned.
5858
* `listing_id` - (Optional) The unique identifier for the listing.

0 commit comments

Comments
 (0)