Skip to content

Commit

Permalink
fix(is_share): added empty check and moved source_share_crn outside (I…
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm authored and Srikant Sahu committed Sep 24, 2024
1 parent 38f08cc commit e281918
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ibm/service/vpc/resource_ibm_is_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,23 +1096,24 @@ func resourceIbmIsShareCreate(context context.Context, d *schema.ResourceData, m
sharePrototype.SourceShare = &vpcv1.ShareIdentity{
ID: &sourceShare,
}
} else {
sourceShareCRN := d.Get("source_share_crn").(string)
if sourceShareCRN != "" {
sharePrototype.SourceShare = &vpcv1.ShareIdentity{
CRN: &sourceShareCRN,
}
}
replicationCronSpec := d.Get("replication_cron_spec").(string)
sharePrototype.ReplicationCronSpec = &replicationCronSpec
} else if sourceShareCrnIntf, sShareCrnok := d.GetOk("source_share_crn"); sShareCrnok {
sourceShareCRN := sourceShareCrnIntf.(string)
if sourceShareCRN != "" {
sharePrototype.SourceShare = &vpcv1.ShareIdentity{
CRN: &sourceShareCRN,
}
}

replicationCronSpec := d.Get("replication_cron_spec").(string)
sharePrototype.ReplicationCronSpec = &replicationCronSpec
} else {
originShare := d.Get("origin_share")
OriginShareModel := ResourceIBMIsShareMapToShareIdentity(originShare.([]interface{})[0].(map[string]interface{}))

sharePrototype.OriginShare = OriginShareModel

if len(originShare.([]interface{})) > 0 {
OriginShareModel := ResourceIBMIsShareMapToShareIdentity(originShare.([]interface{})[0].(map[string]interface{}))
sharePrototype.OriginShare = OriginShareModel
}
}

if iopsIntf, ok := d.GetOk("iops"); ok {
Expand Down
57 changes: 57 additions & 0 deletions ibm/service/vpc/resource_ibm_is_share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,32 @@ func TestAccIbmIsShareAllArgs(t *testing.T) {
},
})
}
func TestAccIbmIsShareAllArgs_EmptyCheck(t *testing.T) {
var conf vpcv1.Share

name := fmt.Sprintf("tf-fs-name-%d", acctest.RandIntRange(10, 100))
name2 := fmt.Sprintf("tf-fs-name2-%d", acctest.RandIntRange(10, 100))
name3 := fmt.Sprintf("tf-fs-name3-%d", acctest.RandIntRange(10, 100))
name4 := fmt.Sprintf("tf-fs-name4-%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIbmIsShareDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIbmIsShareAllConfigEmptyCheckConfig(name, name2, name3, name4),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckIbmIsShareExists("ibm_is_share.test-share", conf),
resource.TestCheckResourceAttr("ibm_is_share.test-share", "name", name),
resource.TestCheckResourceAttr("ibm_is_share.test-share2", "name", name2),
resource.TestCheckResourceAttr("ibm_is_share.test-share-replica", "name", name3),
resource.TestCheckResourceAttr("ibm_is_share.test-share2-replica-crn", "name", name4),
),
},
},
})
}

func TestAccIbmIsShareReplicaMain(t *testing.T) {
var conf vpcv1.Share
Expand Down Expand Up @@ -432,6 +458,37 @@ func testAccCheckIbmIsShareConfig(vpcName, name string, size int, shareTergetNam
}
`, vpcName, name, acc.ShareProfileName, size, shareTergetName)
}
func testAccCheckIbmIsShareAllConfigEmptyCheckConfig(sharename1, sharename2, sharename3, sharename4 string) string {
return fmt.Sprintf(`
resource "ibm_is_share" "test-share" {
name = "%s"
size = 200
profile = "%s"
zone = "%s"
}
resource "ibm_is_share" "test-share2" {
name = "%s"
size = 200
profile = "%s"
zone = "%s"
}
resource "ibm_is_share" "test-share-replica" {
name = "%s"
profile = "%s"
zone = "%s"
source_share = ibm_is_share.test-share.id
replication_cron_spec = "0 */6 * * *"
}
resource "ibm_is_share" "test-share2-replica-crn" {
name = "%s"
profile = "%s"
zone = "%s"
source_share_crn = ibm_is_share.test-share2.crn
replication_cron_spec = "0 */5 * * *"
}
`, sharename1, acc.ShareProfileName, acc.ISZoneName, sharename2, acc.ShareProfileName, acc.ISZoneName, sharename3, acc.ShareProfileName, acc.ISZoneName2, sharename4, acc.ShareProfileName, acc.ISZoneName3)
}

func testAccCheckIbmIsShareConfigReplica(vpcName, vpcName1, name string, size int, shareTergetName, shareTergetName1, replicaName string) string {
return fmt.Sprintf(`
Expand Down

0 comments on commit e281918

Please sign in to comment.