Skip to content

Commit

Permalink
update catalog management offering instance
Browse files Browse the repository at this point in the history
  • Loading branch information
JonWoodlief authored and hkantare committed May 21, 2021
1 parent eb1807e commit d666dd4
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/IBM/ibm-cos-sdk-go-config v1.1.0
github.com/IBM/keyprotect-go-client v0.7.0
github.com/IBM/networking-go-sdk v0.14.0
github.com/IBM/platform-services-go-sdk v0.18.11
github.com/IBM/platform-services-go-sdk v0.18.12
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/schematics-go-sdk v0.0.2
github.com/IBM/secrets-manager-go-sdk v0.1.19
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ github.com/IBM/platform-services-go-sdk v0.18.7 h1:6XLMcX+dg99emswSTS24winxJ6Vjj
github.com/IBM/platform-services-go-sdk v0.18.7/go.mod h1:yaE+2oxhno9RhKYyvzeektKCajakHkM2R2/gWSJIqfA=
github.com/IBM/platform-services-go-sdk v0.18.11 h1:86o1S+LghQJmmjXfOLcmJ+C5bXsaHQCHtPNbV/VAXv0=
github.com/IBM/platform-services-go-sdk v0.18.11/go.mod h1:yaE+2oxhno9RhKYyvzeektKCajakHkM2R2/gWSJIqfA=
github.com/IBM/platform-services-go-sdk v0.18.12 h1:Xxh3hmbIStKfz7L9E3C1NbHvic/bdRai/pHSpQwHfp8=
github.com/IBM/platform-services-go-sdk v0.18.12/go.mod h1:awc7TZUeGMlToSeMSaWEz34Knf0lQnuGWumcI4pcuoM=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5/go.mod h1:b07XHUVh0XYnQE9s2mqgjYST1h9buaQNqN4EcKhOsX0=
github.com/IBM/schematics-go-sdk v0.0.2 h1:IFdM73VL3xwf/KaTh1IY99hkiTfFRYg5F1JNj69FOEg=
Expand Down
24 changes: 24 additions & 0 deletions ibm/data_source_ibm_cm_offering_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func dataSourceIBMCmOfferingInstance() *schema.Resource {
Computed: true,
Description: "platform CRN for this instance.",
},
"_rev": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Cloudant Revision for this instance",
},
"label": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -82,6 +87,16 @@ func dataSourceIBMCmOfferingInstance() *schema.Resource {
Computed: true,
Description: "designate to install into all namespaces.",
},
"schematics_workspace_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "id of the schematics workspace, for offerings installed through schematics",
},
"resource_group_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "id of the resource group",
},
},
}
}
Expand Down Expand Up @@ -110,6 +125,9 @@ func dataSourceIBMCmOfferingInstanceRead(context context.Context, d *schema.Reso
if err = d.Set("crn", offeringInstance.CRN); err != nil {
return diag.FromErr(fmt.Errorf("Error setting crn: %s", err))
}
if err = d.Set("_rev", offeringInstance.Rev); err != nil {
return diag.FromErr(fmt.Errorf("Error setting _rev: %s", err))
}
if err = d.Set("label", offeringInstance.Label); err != nil {
return diag.FromErr(fmt.Errorf("Error setting label: %s", err))
}
Expand Down Expand Up @@ -137,6 +155,12 @@ func dataSourceIBMCmOfferingInstanceRead(context context.Context, d *schema.Reso
if err = d.Set("cluster_all_namespaces", offeringInstance.ClusterAllNamespaces); err != nil {
return diag.FromErr(fmt.Errorf("Error setting cluster_all_namespaces: %s", err))
}
if err = d.Set("schematics_workspace_id", offeringInstance.SchematicsWorkspaceID); err != nil {
return diag.FromErr(fmt.Errorf("Error setting schematics_workspace_id: %s", err))
}
if err = d.Set("resource_group_id", offeringInstance.ResourceGroupID); err != nil {
return diag.FromErr(fmt.Errorf("Error setting resource_group_id: %s", err))
}

return nil
}
9 changes: 6 additions & 3 deletions ibm/data_source_ibm_cm_offering_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ import (
func TestAccIBMCmOfferingInstanceDataSource(t *testing.T) {
clusterId := os.Getenv("CATMGMT_CLUSTERID")
clusterRegion := os.Getenv("CATMGMT_CLUSTERREGION")
resourceGroupID := os.Getenv("CATMGMT_RGID")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMCmOfferingInstanceDataSourceConfig(clusterId, clusterRegion),
Config: testAccCheckIBMCmOfferingInstanceDataSourceConfig(clusterId, clusterRegion, resourceGroupID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_cm_offering_instance.cm_offering_instance_data", "label"),
resource.TestCheckResourceAttrSet("data.ibm_cm_offering_instance.cm_offering_instance_data", "url"),
resource.TestCheckResourceAttrSet("data.ibm_cm_offering_instance.cm_offering_instance_data", "resource_group_id"),
),
},
},
})
}

func testAccCheckIBMCmOfferingInstanceDataSourceConfig(clusterId string, clusterRegion string) string {
func testAccCheckIBMCmOfferingInstanceDataSourceConfig(clusterId string, clusterRegion string, resourceGroupID string) string {
return fmt.Sprintf(`
resource "ibm_cm_catalog" "cm_catalog" {
Expand Down Expand Up @@ -60,11 +62,12 @@ func testAccCheckIBMCmOfferingInstanceDataSourceConfig(clusterId string, cluster
cluster_region = "%s"
cluster_namespaces = ["tf-cm-data-test"]
cluster_all_namespaces = false
resource_group_id = "%s"
}
data "ibm_cm_offering_instance" "cm_offering_instance_data" {
instance_identifier = ibm_cm_offering_instance.cm_offering_instance.id
}
`, clusterId, clusterRegion)
`, clusterId, clusterRegion, resourceGroupID)
}
46 changes: 45 additions & 1 deletion ibm/resource_ibm_cm_offering_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ibm
import (
"fmt"
"log"
"os"

"github.com/IBM/platform-services-go-sdk/catalogmanagementv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -31,6 +32,11 @@ func resourceIBMCmOfferingInstance() *schema.Resource {
Computed: true,
Description: "platform CRN for this instance.",
},
"_rev": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Cloudant Revision for this instance",
},
"label": &schema.Schema{
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -77,6 +83,16 @@ func resourceIBMCmOfferingInstance() *schema.Resource {
Required: true,
Description: "designate to install into all namespaces.",
},
"schematics_workspace_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "id of the schematics workspace, for offerings installed through schematics",
},
"resource_group_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "id of the resource group",
},
},
}
}
Expand All @@ -94,6 +110,10 @@ func resourceIBMCmOfferingInstanceCreate(d *schema.ResourceData, meta interface{

createOfferingInstanceOptions := &catalogmanagementv1.CreateOfferingInstanceOptions{}

schemID, isfound := os.LookupEnv("IC_SCHEMATICS_WORKSPACE_ID")
if isfound {
createOfferingInstanceOptions.SetSchematicsWorkspaceID(schemID)
}
createOfferingInstanceOptions.SetXAuthRefreshToken(rsConClient.Config.IAMRefreshToken)
if _, ok := d.GetOk("label"); ok {
createOfferingInstanceOptions.SetLabel(d.Get("label").(string))
Expand Down Expand Up @@ -123,6 +143,9 @@ func resourceIBMCmOfferingInstanceCreate(d *schema.ResourceData, meta interface{
if _, ok := d.GetOk("cluster_all_namespaces"); ok {
createOfferingInstanceOptions.SetClusterAllNamespaces(d.Get("cluster_all_namespaces").(bool))
}
if _, ok := d.GetOk("resource_group_id"); ok {
createOfferingInstanceOptions.SetResourceGroupID(d.Get("resource_group_id").(string))
}

offeringInstance, response, err := catalogManagementClient.CreateOfferingInstance(createOfferingInstanceOptions)
if err != nil {
Expand Down Expand Up @@ -163,6 +186,9 @@ func resourceIBMCmOfferingInstanceRead(d *schema.ResourceData, meta interface{})
if err = d.Set("crn", offeringInstance.CRN); err != nil {
return fmt.Errorf("Error setting crn: %s", err)
}
if err = d.Set("_rev", offeringInstance.Rev); err != nil {
return fmt.Errorf("Error setting _rev: %s", err)
}
if err = d.Set("label", offeringInstance.Label); err != nil {
return fmt.Errorf("Error setting label: %s", err)
}
Expand Down Expand Up @@ -192,6 +218,9 @@ func resourceIBMCmOfferingInstanceRead(d *schema.ResourceData, meta interface{})
if err = d.Set("cluster_all_namespaces", offeringInstance.ClusterAllNamespaces); err != nil {
return fmt.Errorf("Error setting cluster_all_namespaces: %s", err)
}
if err = d.Set("schematics_workspace_id", offeringInstance.SchematicsWorkspaceID); err != nil {
return fmt.Errorf("Error setting schematics_workspace_id: %s", err)
}

return nil
}
Expand All @@ -202,6 +231,16 @@ func resourceIBMCmOfferingInstanceUpdate(d *schema.ResourceData, meta interface{
return err
}

getOfferingInstanceOptions := &catalogmanagementv1.GetOfferingInstanceOptions{}

getOfferingInstanceOptions.SetInstanceIdentifier(d.Id())

offeringInstance, response, err := catalogManagementClient.GetOfferingInstance(getOfferingInstanceOptions)
if err != nil {
log.Printf("[DEBUG] Failed to retrieve rev %s\n%s", err, response)
return err
}

rsConClient, err := meta.(ClientSession).BluemixSession()
if err != nil {
return err
Expand All @@ -210,7 +249,9 @@ func resourceIBMCmOfferingInstanceUpdate(d *schema.ResourceData, meta interface{
putOfferingInstanceOptions := &catalogmanagementv1.PutOfferingInstanceOptions{}

putOfferingInstanceOptions.SetInstanceIdentifier(d.Id())
putOfferingInstanceOptions.SetID(d.Id())
putOfferingInstanceOptions.SetXAuthRefreshToken(rsConClient.Config.IAMRefreshToken)
putOfferingInstanceOptions.SetRev(*offeringInstance.Rev)
if _, ok := d.GetOk("label"); ok {
putOfferingInstanceOptions.SetLabel(d.Get("label").(string))
}
Expand Down Expand Up @@ -239,8 +280,11 @@ func resourceIBMCmOfferingInstanceUpdate(d *schema.ResourceData, meta interface{
if _, ok := d.GetOk("cluster_all_namespaces"); ok {
putOfferingInstanceOptions.SetClusterAllNamespaces(d.Get("cluster_all_namespaces").(bool))
}
if _, ok := d.GetOk("resource_group_id"); ok {
putOfferingInstanceOptions.SetResourceGroupID(d.Get("resource_group_id").(string))
}

_, response, err := catalogManagementClient.PutOfferingInstance(putOfferingInstanceOptions)
_, response, err = catalogManagementClient.PutOfferingInstance(putOfferingInstanceOptions)
if err != nil {
log.Printf("[DEBUG] PutOfferingInstance failed %s\n%s", err, response)
return err
Expand Down
4 changes: 3 additions & 1 deletion website/docs/d/cm_offering_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ Review the output parameters that you can access after your data source is creat
- `cluster_namespaces` - (String) The list of target namespaces to install.
- `cluster_all_namespaces` - (String) Designate to install into all namespaces.
- `crn` - (String) The platform CRN for an instance.
- `_rev` - (string) The cloudant revisionn of this object
- `id` - (String) The unique identifier of the `cm_offering_instance`.
- `kind_format` - (String) The format this instance has such as `helm`, `operator`.
- `label` - (String) The label for an instance.
- `offering_id` - (String) The offering ID the instance that is created from.
- `url` - (String) The URL reference to an object.
- `version` - (String) The version an instance is installed from (but not from the version ID).

- `schematics_workspace_id` - (String) The ID of the schematics workspace, for offering instances installed through schematics
- `resource_group_id` - (String) The ID of the resource group this instance was installed into
5 changes: 2 additions & 3 deletions website/docs/r/cm_offering_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ Review the output parameters that you can access after your resource is created.
- `crn` - (String) The platform CRN for an instance.
- `id` - (String) The unique identifier of the `cm_offering_instance`.
- `url` - (String) The URL reference to an object.



- `_rev` - (String) The cloudant revision of this object
- `schematics_workspace_id` - (String) The ID of the schematics workspace used to install this offering, if applicable

0 comments on commit d666dd4

Please sign in to comment.