diff --git a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template.go b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template.go index 1bd1d31f29..a653a77a38 100644 --- a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template.go +++ b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template.go @@ -388,6 +388,17 @@ func resourceIBMIAMAccessGroupTemplateCreate(context context.Context, d *schema. } version, _ := strconv.Atoi(*templateResponse.Version) + if d.Get("committed").(bool) { + commitTemplateOptions := &iamaccessgroupsv2.CommitTemplateOptions{} + commitTemplateOptions.SetTemplateID(*templateResponse.ID) + commitTemplateOptions.SetVersionNum(*templateResponse.Version) + commitTemplateOptions.SetIfMatch(response.Headers.Get("ETag")) + response, err = iamAccessGroupsClient.CommitTemplateWithContext(context, commitTemplateOptions) + if err != nil { + log.Printf("[DEBUG] CommitTemplateWithContext failed %s\n%s", err, response) + return diag.FromErr(fmt.Errorf("CommitTemplateWithContext failed %s\n%s", err, response)) + } + } d.SetId(fmt.Sprintf("%s/%d", *templateResponse.ID, version)) return resourceIBMIAMAccessGroupTemplateVersionRead(context, d, meta) diff --git a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_test.go b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_test.go index b8a6cc9f11..78902bba8d 100644 --- a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_test.go +++ b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_test.go @@ -35,6 +35,7 @@ func TestAccIBMIAMAccessGroupTemplateBasic(t *testing.T) { testAccCheckIBMIAMAccessGroupTemplateVersionExists("ibm_iam_access_group_template.template", conf), resource.TestCheckResourceAttr("ibm_iam_access_group_template.template", "name", name), resource.TestCheckResourceAttr("ibm_iam_access_group_template.template", "group.0.name", agName), + resource.TestCheckResourceAttr("ibm_iam_access_group_template.template", "committed", "true"), ), }, }, @@ -106,6 +107,7 @@ func testAccCheckIBMIAMAccessGroupTemplateConfigBasic(name string, agName string group { name = "%s" } + committed = true } `, name, agName) } diff --git a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_version.go b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_version.go index 33245b0da6..a9a0ced3c0 100644 --- a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_version.go +++ b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_version.go @@ -390,6 +390,18 @@ func resourceIBMIAMAccessGroupTemplateVersionCreate(context context.Context, d * return diag.FromErr(fmt.Errorf("CreateTemplateVersionWithContext failed %s\n%s", err, response)) } + if d.Get("committed").(bool) { + commitTemplateOptions := &iamaccessgroupsv2.CommitTemplateOptions{} + commitTemplateOptions.SetTemplateID(*templateVersionResponse.ID) + commitTemplateOptions.SetVersionNum(*templateVersionResponse.Version) + commitTemplateOptions.SetIfMatch(response.Headers.Get("ETag")) + response, err = iamAccessGroupsClient.CommitTemplateWithContext(context, commitTemplateOptions) + if err != nil { + log.Printf("[DEBUG] CommitTemplateWithContext failed %s\n%s", err, response) + return diag.FromErr(fmt.Errorf("CommitTemplateWithContext failed %s\n%s", err, response)) + } + } + d.SetId(fmt.Sprintf("%s/%s", *templateVersionResponse.ID, *templateVersionResponse.Version)) return resourceIBMIAMAccessGroupTemplateVersionRead(context, d, meta) diff --git a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_version_test.go b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_version_test.go index cd0584ff31..7f27f48196 100644 --- a/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_version_test.go +++ b/ibm/service/iamaccessgroup/resource_ibm_iam_access_group_template_version_test.go @@ -36,6 +36,7 @@ func TestAccIBMIAMAccessGroupTemplateVersion(t *testing.T) { resource.TestCheckResourceAttr("ibm_iam_access_group_template_version.template", "group.0.name", versionAGName), resource.TestCheckResourceAttr("ibm_iam_access_group_template_version.template", "name", name), resource.TestCheckResourceAttr("ibm_iam_access_group_template.template", "name", name), + resource.TestCheckResourceAttr("ibm_iam_access_group_template_version.template", "committed", "true"), ), }, }, @@ -52,7 +53,7 @@ func TestAccIBMIAMAccessGroupTemplateVersionUpdateWithCommit(t *testing.T) { CheckDestroy: testAccCheckIBMIAMAccessGroupTemplateVersionDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMIAMAccessGroupTemplateVersionConfigBasic(name, agName, versionAGName), + Config: testAccCheckIBMIAMAccessGroupTemplateVersionConfigBasicWithoutCommit(name, agName, versionAGName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckIBMIAMAccessGroupTemplateVersionExists("ibm_iam_access_group_template_version.template", conf), resource.TestCheckResourceAttr("ibm_iam_access_group_template.template", "group.0.name", agName), @@ -87,6 +88,34 @@ func testAccCheckIBMIAMAccessGroupTemplateVersionConfigBasic(name string, agName } } + resource "ibm_iam_access_group_template_version" "template" { + template_id = ibm_iam_access_group_template.template.template_id + name = ibm_iam_access_group_template.template.name + description = "Testing4" + group { + name = "%s" + assertions { + action_controls { + add = false + remove = true + } + } + } + committed = true + } + `, name, agName, versionAGName) +} + +func testAccCheckIBMIAMAccessGroupTemplateVersionConfigBasicWithoutCommit(name string, agName string, versionAGName string) string { + return fmt.Sprintf(` + resource "ibm_iam_access_group_template" "template" { + name = "%s" + description = "Test Terraform Description" + group { + name = "%s" + } + } + resource "ibm_iam_access_group_template_version" "template" { template_id = ibm_iam_access_group_template.template.template_id name = ibm_iam_access_group_template.template.name