Skip to content

Commit

Permalink
add resource group to cm_catalog resource and datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
JonWoodlief committed Nov 8, 2021
1 parent f4d9cfe commit a19be28
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ibm/data_source_ibm_cm_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func dataSourceIBMCmCatalog() *schema.Resource {
Computed: true,
Description: "URL path to offerings.",
},
"resource_group_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Resource Group ID",
},
},
}
}
Expand Down Expand Up @@ -111,5 +116,9 @@ func dataSourceIBMCmCatalogRead(context context.Context, d *schema.ResourceData,
if err = d.Set("kind", catalog.Kind); err != nil {
return diag.FromErr(fmt.Errorf("Error setting kind: %s", err))
}
if err = d.Set("resource_group_id", catalog.ResourceGroupID); err != nil {
return diag.FromErr(fmt.Errorf("Error setting resource_group_id: %s", err))
}

return nil
}
11 changes: 8 additions & 3 deletions ibm/data_source_ibm_cm_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@ package ibm

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccIBMCmCatalogDataSource(t *testing.T) {
ResourceGroupID := os.Getenv("CATMGMT_RESOURCE_GROUP_ID")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMCmCatalogDataSourceConfig(),
Config: testAccCheckIBMCmCatalogDataSourceConfig(ResourceGroupID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_cm_catalog.cm_catalog_data", "label"),
resource.TestCheckResourceAttrSet("data.ibm_cm_catalog.cm_catalog_data", "crn"),
resource.TestCheckResourceAttrSet("data.ibm_cm_catalog.cm_catalog_data", "kind"),
resource.TestCheckResourceAttrSet("ibm_cm_catalog.cm_catalog", "resource_group_id"),
),
},
resource.TestStep{
Expand All @@ -30,24 +33,26 @@ func TestAccIBMCmCatalogDataSource(t *testing.T) {
resource.TestCheckResourceAttrSet("data.ibm_cm_catalog.cm_catalog_data", "label"),
resource.TestCheckResourceAttrSet("data.ibm_cm_catalog.cm_catalog_data", "crn"),
resource.TestCheckResourceAttrSet("data.ibm_cm_catalog.cm_catalog_data", "kind"),
resource.TestCheckResourceAttrSet("ibm_cm_catalog.cm_catalog", "resource_group_id"),
),
},
},
})
}

func testAccCheckIBMCmCatalogDataSourceConfig() string {
func testAccCheckIBMCmCatalogDataSourceConfig(resourceGroupID string) string {
return fmt.Sprintf(`
resource "ibm_cm_catalog" "cm_catalog" {
label = "tf_test_datasource_catalog"
short_description = "testing terraform provider with catalog"
resource_group_id = "%s"
}
data "ibm_cm_catalog" "cm_catalog_data" {
catalog_identifier = ibm_cm_catalog.cm_catalog.id
}
`)
`, resourceGroupID)
}

func testAccCheckIBMCmCatalogDataSourceConfigDefault() string {
Expand Down
13 changes: 13 additions & 0 deletions ibm/resource_ibm_cm_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func resourceIBMCmCatalog() *schema.Resource {
Computed: true,
Description: "URL path to offerings.",
},
"resource_group_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
ForceNew: true,
Optional: true,
Description: "Resource Group ID",
},
},
}
}
Expand Down Expand Up @@ -94,6 +101,9 @@ func resourceIBMCmCatalogCreate(d *schema.ResourceData, meta interface{}) error
if _, ok := d.GetOk("kind"); ok {
createCatalogOptions.SetKind(d.Get("kind").(string))
}
if _, ok := d.GetOk("resource_group_id"); ok {
createCatalogOptions.SetResourceGroupID(d.Get("resource_group_id").(string))
}

catalog, response, err := catalogManagementClient.CreateCatalog(createCatalogOptions)
if err != nil {
Expand Down Expand Up @@ -152,6 +162,9 @@ func resourceIBMCmCatalogRead(d *schema.ResourceData, meta interface{}) error {
if err = d.Set("kind", catalog.Kind); err != nil {
return fmt.Errorf("Error setting kind: %s", err)
}
if err = d.Set("resource_group_id", catalog.ResourceGroupID); err != nil {
return fmt.Errorf("Error setting resource_group_id: %s", err)
}

return nil
}
Expand Down
1 change: 1 addition & 0 deletions ibm/resource_ibm_cm_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccIBMCmCatalog(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckIBMCmCatalogExists("ibm_cm_catalog.cm_catalog"),
resource.TestCheckResourceAttrSet("ibm_cm_catalog.cm_catalog", "label"),
resource.TestCheckResourceAttrSet("ibm_cm_catalog.cm_catalog", "resource_group_id"),
),
},
resource.TestStep{
Expand Down
3 changes: 2 additions & 1 deletion website/docs/d/cm_catalog.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ In addition to the argument reference list, you can access the following attribu
- `catalog_icon_url` - (String) The URL for an icon associated with the catalog.
- `crn` - (String) The CRN associated with the catalog.
- `id` - (String) The unique identifier of the `ibm_cm_catalog`.
- `label` - (String) Display the name in the requested language.
- `kind` - (String) Kind of catalog, offering or vpe.
- `label` - (String) Display the name in the requested language.
- `offerings_url` - (String) URL path to the offerings.
- `resource_group_id` - (String) The ID of the resource group this catalog is in
- `short_description` - (String) The description in the requested language.
- `tags` - (String) The list of tags associated with this catalog.
- `url` - (String) The URL for the specific catalog.
3 changes: 2 additions & 1 deletion website/docs/r/cm_catalog.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ resource "ibm_cm_catalog" "cm_catalog" {
Review the argument reference that you can specify for your resource.

- `label` - (Required, Forces new resource, String) The display name in the requested language.
- `short_description` - (Optional, Forces new resource, String) The short description in the requested language.
- `kind` - (Optional, Forces new resource, Defaults to offering, String) The kind of the catalog, offering or vpe.
- `resource_group_id` - (Optional, Forces new resource, String) The ID of the resource group this catalog will be provisioned in
- `short_description` - (Optional, Forces new resource, String) The short description in the requested language.


## Attribute reference
Expand Down

0 comments on commit a19be28

Please sign in to comment.