diff --git a/examples/ibm-is-ng/main.tf b/examples/ibm-is-ng/main.tf index 9a6d9de5a2..687ccfcaec 100644 --- a/examples/ibm-is-ng/main.tf +++ b/examples/ibm-is-ng/main.tf @@ -767,7 +767,7 @@ resource "ibm_is_instance" "instance8" { } catalog_offering { version_crn = data.ibm_is_images.imageslist.images.0.catalog_offering.0.version.0.crn - plan_crn = "crn:v1:bluemix:public:globalcatalog-collection:global:a/123456:51c9e0db-2911-45a6-adb0-ac5332d27cf2:plan:sw.51c9e0db-2911-45a6-adb0-ac5332d27cf2.772c0dbe-aa62-482e-adbe-a3fc20101e0e" + plan_crn = "crn:v1:bluemix:public:globalcatalog-collection:global:a/123456:51c9e0db-2911-45a6-adb0-ac5332d27cf2:plan:sw.51c9e0db-2911-45a6-adb0-ac5332d27cf2.772c0dbe-aa62-482e-adbe-a3fc20101e0e" } vpc = ibm_is_vpc.vpc2.id zone = "us-south-2" @@ -778,7 +778,7 @@ resource "ibm_is_instance_template" "instancetemplate3" { name = "instancetemplate-3" catalog_offering { version_crn = data.ibm_is_images.imageslist.images.0.catalog_offering.0.version.0.crn - plan_crn = "crn:v1:bluemix:public:globalcatalog-collection:global:a/123456:51c9e0db-2911-45a6-adb0-ac5332d27cf2:plan:sw.51c9e0db-2911-45a6-adb0-ac5332d27cf2.772c0dbe-aa62-482e-adbe-a3fc20101e0e" + plan_crn = "crn:v1:bluemix:public:globalcatalog-collection:global:a/123456:51c9e0db-2911-45a6-adb0-ac5332d27cf2:plan:sw.51c9e0db-2911-45a6-adb0-ac5332d27cf2.772c0dbe-aa62-482e-adbe-a3fc20101e0e" } profile = var.profile @@ -1298,6 +1298,22 @@ data "ibm_is_share" "is_share" { data "ibm_is_shares" "is_shares" { } +resource "ibm_is_share_snapshot" "example" { + name = "my-example-share-snapshot" + share = ibm_is_share.share.id + tags = ["my-example-share-snapshot-tag"] +} +data "ibm_is_share_snapshots" "example" { + share = ibm_is_share.share.id +} + +// Retrieve all the snapshots from all the shares +data "ibm_is_share_snapshots" "example1" { +} +data "ibm_is_share_snapshot" "example1" { + share = ibm_is_share.share.id + share_snapshot = ibm_is_share_snapshot.example.share_snapshot +} // vpc dns resolution bindings // list all dns resolution bindings on a vpc @@ -1629,16 +1645,16 @@ data "ibm_is_reservation" "example" { // cluster examples # ============================================================================================================= -variable prefix { +variable "prefix" { default = "test-cluster" } -variable is_instances_resource_group_id { +variable "is_instances_resource_group_id" { default = "efhiorho4388yf348y83yvchrc083h0r30c" } -variable region { +variable "region" { default = "us-east" } -variable is_instances_name { +variable "is_instances_name" { default = "test-vsi" } data "ibm_is_cluster_network_profile" "is_cluster_network_profile_instance" { @@ -1662,18 +1678,18 @@ resource "ibm_is_subnet" "is_subnet" { zone = "${var.region}-3" } -data ibm_is_instance_profile is_instance_profile_instance{ +data "ibm_is_instance_profile" "is_instance_profile_instance" { name = "gx3d-160x1792x8h100" } -data ibm_is_instance_profiles is_instance_profiles_instance{ +data "ibm_is_instance_profiles" "is_instance_profiles_instance" { } data "ibm_is_image" "is_image" { name = "ibm-ubuntu-20-04-6-minimal-amd64-6" } resource "ibm_is_cluster_network" "is_cluster_network_instance" { - name = "${var.prefix}-cluster" - profile = "h100" - resource_group = var.is_instances_resource_group_id + name = "${var.prefix}-cluster" + profile = "h100" + resource_group = var.is_instances_resource_group_id subnet_prefixes { cidr = "10.1.0.0/24" } @@ -1683,7 +1699,7 @@ resource "ibm_is_cluster_network" "is_cluster_network_instance" { zone = "${var.region}-3" } resource "ibm_is_cluster_network" "is_cluster_network_instance" { - name = "${var.prefix}-cluster-updated" + name = "${var.prefix}-cluster-updated" profile = "h100" subnet_prefixes { cidr = "10.0.0.0/24" @@ -1694,21 +1710,21 @@ resource "ibm_is_cluster_network" "is_cluster_network_instance" { zone = ibm_is_subnet.is_subnet.zone } resource "ibm_is_cluster_network_subnet" "is_cluster_network_subnet_instance" { - cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id - name = "${var.prefix}-cluster-subnet" + cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id + name = "${var.prefix}-cluster-subnet" total_ipv4_address_count = 64 } resource "ibm_is_cluster_network_subnet_reserved_ip" "is_cluster_network_subnet_reserved_ip_instance" { - cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id + cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id cluster_network_subnet_id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - address = "10.1.0.4" - name = "${var.prefix}-cluster-subnet-r-ip" + address = "10.1.0.4" + name = "${var.prefix}-cluster-subnet-r-ip" } resource "ibm_is_cluster_network_interface" "is_cluster_network_interface_instance" { cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id - name = "${var.prefix}-cluster-ni" + name = "${var.prefix}-cluster-ni" primary_ip { id = ibm_is_cluster_network_subnet_reserved_ip.is_cluster_network_subnet_reserved_ip_instance.cluster_network_subnet_reserved_ip_id } @@ -1729,42 +1745,42 @@ resource "ibm_is_instance_template" "is_instance_template" { } } cluster_network_attachments { - cluster_network_interface{ + cluster_network_interface { id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } } cluster_network_attachments { - cluster_network_interface{ + cluster_network_interface { id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } } cluster_network_attachments { - cluster_network_interface{ + cluster_network_interface { id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } } cluster_network_attachments { - cluster_network_interface{ + cluster_network_interface { id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } } cluster_network_attachments { - cluster_network_interface{ + cluster_network_interface { id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } } cluster_network_attachments { - cluster_network_interface{ + cluster_network_interface { id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } } cluster_network_attachments { - cluster_network_interface{ + cluster_network_interface { id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } } cluster_network_attachments { - cluster_network_interface{ + cluster_network_interface { id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } } @@ -1786,20 +1802,20 @@ resource "ibm_is_instance" "is_instance" { subnet = ibm_is_subnet.is_subnet.id } cluster_network_attachments { - name = "cna-1" - cluster_network_interface{ + name = "cna-1" + cluster_network_interface { auto_delete = true - name = "cni-1" + name = "cni-1" subnet { id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } } } cluster_network_attachments { - name = "cna-2" - cluster_network_interface{ + name = "cna-2" + cluster_network_interface { auto_delete = true - name = "cni-2" + name = "cni-2" subnet { id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } @@ -1807,59 +1823,59 @@ resource "ibm_is_instance" "is_instance" { } cluster_network_attachments { name = "cna-3" - cluster_network_interface{ + cluster_network_interface { auto_delete = true - name = "cni-3" + name = "cni-3" subnet { id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } } } cluster_network_attachments { - name = "cna-4" - cluster_network_interface{ + name = "cna-4" + cluster_network_interface { auto_delete = true - name = "cni-4" + name = "cni-4" subnet { id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } } } cluster_network_attachments { - name = "cna-5" - cluster_network_interface{ + name = "cna-5" + cluster_network_interface { auto_delete = true - name = "cni-5" + name = "cni-5" subnet { id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } } } cluster_network_attachments { - name = "cna-6" - cluster_network_interface{ + name = "cna-6" + cluster_network_interface { auto_delete = true - name = "cni-6" + name = "cni-6" subnet { id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } } } cluster_network_attachments { - name = "cna-7" - cluster_network_interface{ + name = "cna-7" + cluster_network_interface { auto_delete = true - name = "cni-7" + name = "cni-7" subnet { id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } } } cluster_network_attachments { - name = "cna-8" - cluster_network_interface{ + name = "cna-8" + cluster_network_interface { auto_delete = true - name = "cni-8" + name = "cni-8" subnet { id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } @@ -1871,131 +1887,131 @@ resource "ibm_is_instance" "is_instance" { } resource "ibm_is_instance_action" "is_instance_stop_before" { - action = "stop" - instance = ibm_is_instance.is_instance.id + action = "stop" + instance = ibm_is_instance.is_instance.id } resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance" { - depends_on = [ibm_is_instance_action.is_instance_stop_before] - instance_id = ibm_is_instance.is_instance.id - before { - id = ibm_is_instance.is_instance.cluster_network_attachments.0.id - } - cluster_network_interface { - name = "my-cluster-network-interface" - subnet { - id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - } + depends_on = [ibm_is_instance_action.is_instance_stop_before] + instance_id = ibm_is_instance.is_instance.id + before { + id = ibm_is_instance.is_instance.cluster_network_attachments.0.id + } + cluster_network_interface { + name = "my-cluster-network-interface" + subnet { + id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } - name = "cna-9" + } + name = "cna-9" } resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance10" { - depends_on = [ibm_is_instance_action.is_instance_stop_before] - instance_id = ibm_is_instance.is_instance.id - before { - id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance.instance_cluster_network_attachment_id - } - cluster_network_interface { - name = "my-cluster-network-interface-10" - subnet { - id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - } + depends_on = [ibm_is_instance_action.is_instance_stop_before] + instance_id = ibm_is_instance.is_instance.id + before { + id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance.instance_cluster_network_attachment_id + } + cluster_network_interface { + name = "my-cluster-network-interface-10" + subnet { + id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } - name = "cna-10" + } + name = "cna-10" } resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance11" { - depends_on = [ibm_is_instance_action.is_instance_stop_before] - instance_id = ibm_is_instance.is_instance.id - before { - id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance10.instance_cluster_network_attachment_id -} - cluster_network_interface { - name = "my-cluster-network-interface-11" - subnet { - id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - } + depends_on = [ibm_is_instance_action.is_instance_stop_before] + instance_id = ibm_is_instance.is_instance.id + before { + id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance10.instance_cluster_network_attachment_id + } + cluster_network_interface { + name = "my-cluster-network-interface-11" + subnet { + id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } - name = "cna-11" + } + name = "cna-11" } resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance12" { - depends_on = [ibm_is_instance_action.is_instance_stop_before] - instance_id = ibm_is_instance.is_instance.id - before { - id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance11.instance_cluster_network_attachment_id -} - cluster_network_interface { - name = "my-cluster-network-interface12" - subnet { - id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - } + depends_on = [ibm_is_instance_action.is_instance_stop_before] + instance_id = ibm_is_instance.is_instance.id + before { + id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance11.instance_cluster_network_attachment_id + } + cluster_network_interface { + name = "my-cluster-network-interface12" + subnet { + id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } - name = "cna-12" + } + name = "cna-12" } resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance13" { - depends_on = [ibm_is_instance_action.is_instance_stop_before] - instance_id = ibm_is_instance.is_instance.id - before { - id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance12.instance_cluster_network_attachment_id - } - cluster_network_interface { - name = "my-cluster-network-interface13" - subnet { - id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - } + depends_on = [ibm_is_instance_action.is_instance_stop_before] + instance_id = ibm_is_instance.is_instance.id + before { + id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance12.instance_cluster_network_attachment_id + } + cluster_network_interface { + name = "my-cluster-network-interface13" + subnet { + id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } - name = "cna-13" + } + name = "cna-13" } resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance14" { - depends_on = [ibm_is_instance_action.is_instance_stop_before] - instance_id = ibm_is_instance.is_instance.id - before { - id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance13.instance_cluster_network_attachment_id - } - cluster_network_interface { - name = "my-cluster-network-interface14" - subnet { - id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - } + depends_on = [ibm_is_instance_action.is_instance_stop_before] + instance_id = ibm_is_instance.is_instance.id + before { + id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance13.instance_cluster_network_attachment_id + } + cluster_network_interface { + name = "my-cluster-network-interface14" + subnet { + id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } - name = "cna-149" + } + name = "cna-149" } resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance15" { - depends_on = [ibm_is_instance_action.is_instance_stop_before] - instance_id = ibm_is_instance.is_instance.id - before { - id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance14.instance_cluster_network_attachment_id - } - cluster_network_interface { - name = "my-cluster-network-interface15" - subnet { - id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - } + depends_on = [ibm_is_instance_action.is_instance_stop_before] + instance_id = ibm_is_instance.is_instance.id + before { + id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance14.instance_cluster_network_attachment_id + } + cluster_network_interface { + name = "my-cluster-network-interface15" + subnet { + id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } - name = "cna-15" + } + name = "cna-15" } resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance16" { - depends_on = [ibm_is_instance_action.is_instance_stop_before] - instance_id = ibm_is_instance.is_instance.id - before { - id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance15.instance_cluster_network_attachment_id - } - cluster_network_interface { - name = "my-cluster-network-interface16" - subnet { - id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id - } + depends_on = [ibm_is_instance_action.is_instance_stop_before] + instance_id = ibm_is_instance.is_instance.id + before { + id = ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance15.instance_cluster_network_attachment_id + } + cluster_network_interface { + name = "my-cluster-network-interface16" + subnet { + id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } - name = "cna-16" + } + name = "cna-16" } resource "ibm_is_instance_action" "is_instance_start_after" { - # depends_on = [ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance16] - action = "start" - instance = ibm_is_instance.is_instance.id + # depends_on = [ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance16] + action = "start" + instance = ibm_is_instance.is_instance.id } resource "ibm_is_instance_action" "is_instance_stop_update" { - # depends_on = [ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance16] - action = "stop" - instance = ibm_is_instance.is_instance.id + # depends_on = [ibm_is_instance_cluster_network_attachment.is_instance_cluster_network_attachment_instance16] + action = "stop" + instance = ibm_is_instance.is_instance.id } data "ibm_is_cluster_network" "is_cluster_network_instance" { @@ -2005,7 +2021,7 @@ data "ibm_is_cluster_networks" "is_cluster_networks_instance" { } data "ibm_is_cluster_network_interface" "is_cluster_network_interface_instance" { - cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id + cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id cluster_network_interface_id = ibm_is_cluster_network_interface.is_cluster_network_interface_instance.cluster_network_interface_id } data "ibm_is_cluster_network_interfaces" "is_cluster_network_interfaces_instance" { @@ -2013,20 +2029,20 @@ data "ibm_is_cluster_network_interfaces" "is_cluster_network_interfaces_instance } data "ibm_is_cluster_network_subnet" "is_cluster_network_subnet_instance" { - cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id + cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id cluster_network_subnet_id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } data "ibm_is_cluster_network_subnets" "is_cluster_network_subnets_instance" { cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id } data "ibm_is_cluster_network_subnet_reserved_ip" "is_cluster_network_subnet_reserved_ip_instance" { - cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id - cluster_network_subnet_id =ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id + cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id + cluster_network_subnet_id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id cluster_network_subnet_reserved_ip_id = ibm_is_cluster_network_subnet_reserved_ip.is_cluster_network_subnet_reserved_ip_instance.cluster_network_subnet_reserved_ip_id } data "ibm_is_cluster_network_subnet_reserved_ips" "is_cluster_network_subnet_reserved_ips_instance" { - cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id + cluster_network_id = ibm_is_cluster_network.is_cluster_network_instance.id cluster_network_subnet_id = ibm_is_cluster_network_subnet.is_cluster_network_subnet_instance.cluster_network_subnet_id } @@ -2039,7 +2055,7 @@ data "ibm_is_instance" "is_instance_instance" { data "ibm_is_instances" "is_instances_instance" { } data "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance" { - instance_id = ibm_is_instance.is_instance.id + instance_id = ibm_is_instance.is_instance.id instance_cluster_network_attachment_id = ibm_is_instance.is_instance.cluster_network_attachments.0.id } data "ibm_is_instance_cluster_network_attachments" "is_instance_cluster_network_attachments_instance" { diff --git a/go.mod b/go.mod index 5f28ac1d48..23605d58cb 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,7 @@ require ( github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7 github.com/IBM/vmware-go-sdk v0.1.2 github.com/IBM/vpc-beta-go-sdk v0.8.0 - github.com/IBM/vpc-go-sdk v0.63.1 + github.com/IBM/vpc-go-sdk v0.64.0 github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5 github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2 github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0 diff --git a/go.sum b/go.sum index 15c17f91c9..5d4ef78264 100644 --- a/go.sum +++ b/go.sum @@ -173,8 +173,8 @@ github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w github.com/IBM/vmware-go-sdk v0.1.2/go.mod h1:2UGPBJju3jiv5VKKBBm9a5L6bzF/aJdKOKAzJ7HaOjA= github.com/IBM/vpc-beta-go-sdk v0.8.0 h1:cEPpv4iw3Ba5W2d0AWg3TIbKeJ8y1nPuUuibR5Jt9eE= github.com/IBM/vpc-beta-go-sdk v0.8.0/go.mod h1:hORgIyTFRzXrZIK9IohaWmCRBBlYiDRagsufi7M6akE= -github.com/IBM/vpc-go-sdk v0.63.1 h1:HqQeq2wGI2pF4y0/m18EaPsOEEXFjyml+xwlLC9AiXE= -github.com/IBM/vpc-go-sdk v0.63.1/go.mod h1:VBR6bAznHsNCFA89Ue4JFQpqCcFp8F5neqbCFCyks4Q= +github.com/IBM/vpc-go-sdk v0.64.0 h1:0x2jakapXxXYTTr0EdrwuXa6h0couSK+FTDGxd8jChA= +github.com/IBM/vpc-go-sdk v0.64.0/go.mod h1:VBR6bAznHsNCFA89Ue4JFQpqCcFp8F5neqbCFCyks4Q= github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0= github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56/go.mod h1:Zb3OT4l0mf7P/GOs2w2Ilj5sdm5Whoq3pa24dAEBHFc= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index f758b20e4c..77346aa222 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -551,6 +551,8 @@ func Provider() *schema.Provider { "ibm_is_share_profiles": vpc.DataSourceIbmIsShareProfiles(), "ibm_is_share_accessor_bindings": vpc.DataSourceIBMIsShareAccessorBindings(), "ibm_is_share_accessor_binding": vpc.DataSourceIBMIsShareAccessorBinding(), + "ibm_is_share_snapshot": vpc.DataSourceIBMIsShareSnapshot(), + "ibm_is_share_snapshots": vpc.DataSourceIBMIsShareSnapshots(), "ibm_is_virtual_network_interface": vpc.DataSourceIBMIsVirtualNetworkInterface(), "ibm_is_virtual_network_interfaces": vpc.DataSourceIBMIsVirtualNetworkInterfaces(), @@ -1255,6 +1257,7 @@ func Provider() *schema.Provider { "ibm_is_share_replica_operations": vpc.ResourceIbmIsShareReplicaOperations(), "ibm_is_share_mount_target": vpc.ResourceIBMIsShareMountTarget(), "ibm_is_share_delete_accessor_binding": vpc.ResourceIbmIsShareDeleteAccessorBinding(), + "ibm_is_share_snapshot": vpc.ResourceIBMIsShareSnapshot(), "ibm_is_subnet": vpc.ResourceIBMISSubnet(), "ibm_is_reservation": vpc.ResourceIBMISReservation(), "ibm_is_reservation_activate": vpc.ResourceIBMISReservationActivate(), @@ -1951,6 +1954,7 @@ func Validator() validate.ValidatorDict { "ibm_is_share": vpc.ResourceIbmIsShareValidator(), "ibm_is_share_replica_operations": vpc.ResourceIbmIsShareReplicaOperationsValidator(), "ibm_is_share_mount_target": vpc.ResourceIBMIsShareMountTargetValidator(), + "ibm_is_share_snapshot": vpc.ResourceIBMIsShareSnapshotValidator(), "ibm_is_snapshot": vpc.ResourceIBMISSnapshotValidator(), "ibm_is_snapshot_consistency_group": vpc.ResourceIBMIsSnapshotConsistencyGroupValidator(), "ibm_is_ssh_key": vpc.ResourceIBMISSHKeyValidator(), diff --git a/ibm/service/vpc/data_source_ibm_is_backup_policy_job.go b/ibm/service/vpc/data_source_ibm_is_backup_policy_job.go index 0a2defd776..3bbd88d3e2 100644 --- a/ibm/service/vpc/data_source_ibm_is_backup_policy_job.go +++ b/ibm/service/vpc/data_source_ibm_is_backup_policy_job.go @@ -238,6 +238,49 @@ func DataSourceIBMIsBackupPolicyJob() *schema.Resource { }, }, }, + "source_share": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The source share this backup was created from (may be[deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)).", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The CRN for this volume.", + }, + "deleted": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates the referenced resource has been deleted and providessome supplementary information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about deleted resources.", + }, + }, + }, + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this volume.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this volume.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique user-defined name for this volume.", + }, + }, + }, + }, "status": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -307,6 +350,53 @@ func DataSourceIBMIsBackupPolicyJob() *schema.Resource { Computed: true, Description: "The user-defined name for this snapshot.", }, + "remote": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the referenced resource is remote to thisaccount, and identifies the owning account.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this account.", + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + }, + }, + }, + "region": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this region.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The globally unique name for this region.", + }, + }, + }, + }, + }, + }, + }, "resource_type": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -384,9 +474,21 @@ func dataSourceIBMIsBackupPolicyJobRead(context context.Context, d *schema.Resou return diag.FromErr(fmt.Errorf("Error setting source_instance %s", err)) } } + case "*vpcv1.BackupPolicyJobSourceShareReference": + { + jobSource := backupPolicyJob.Source.(*vpcv1.BackupPolicyJobSourceShareReference) + sourceShareList := []map[string]interface{}{} + sourceShareMap := dataShareBackupPolicyJobSourceShareReferenceToMap(jobSource) + sourceShareList = append(sourceShareList, sourceShareMap) + err = d.Set("source_share", sourceShareList) + if err != nil { + return diag.FromErr(fmt.Errorf("Error setting source_share %s", err)) + } + } } } + if err = d.Set("status", backupPolicyJob.Status); err != nil { return diag.FromErr(fmt.Errorf("Error setting status: %s", err)) } @@ -612,19 +714,19 @@ func dataSourceBackupPolicyJobStatusReasonsToMap(statusReasonsItem vpcv1.BackupP return statusReasonsMap } -func dataSourceBackupPolicyJobFlattenTargetSnapshot(result []vpcv1.SnapshotReference) (finalList []map[string]interface{}) { +func dataSourceBackupPolicyJobFlattenTargetSnapshot(result []vpcv1.BackupPolicyTargetSnapshotIntf) (finalList []map[string]interface{}) { finalList = []map[string]interface{}{} for _, snapshotReferenceItem := range result { - finalMap := dataSourceBackupPolicyJobTargetSnapshotToMap(snapshotReferenceItem) + finalMap := dataSourceBackupPolicyJobCollectionJobsTargetSnapshotToMap(snapshotReferenceItem) finalList = append(finalList, finalMap) } return finalList } -func dataSourceBackupPolicyJobTargetSnapshotToMap(targetSnapshotItem vpcv1.SnapshotReference) (targetSnapshotMap map[string]interface{}) { +func dataSourceBackupPolicyJobTargetSnapshotToMap(targetSnapshotItemIntf vpcv1.BackupPolicyTargetSnapshotIntf) (targetSnapshotMap map[string]interface{}) { targetSnapshotMap = map[string]interface{}{} - + targetSnapshotItem := targetSnapshotItemIntf.(*vpcv1.BackupPolicyTargetSnapshot) if targetSnapshotItem.CRN != nil { targetSnapshotMap["crn"] = targetSnapshotItem.CRN } diff --git a/ibm/service/vpc/data_source_ibm_is_backup_policy_jobs.go b/ibm/service/vpc/data_source_ibm_is_backup_policy_jobs.go index e2eb690f34..060452aad5 100644 --- a/ibm/service/vpc/data_source_ibm_is_backup_policy_jobs.go +++ b/ibm/service/vpc/data_source_ibm_is_backup_policy_jobs.go @@ -277,6 +277,49 @@ func DataSourceIBMIsBackupPolicyJobs() *schema.Resource { }, }, }, + "source_share": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The source share this backup was created from (may be[deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)).", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The CRN for this volume.", + }, + "deleted": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates the referenced resource has been deleted and providessome supplementary information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about deleted resources.", + }, + }, + }, + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this volume.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this volume.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique user-defined name for this volume.", + }, + }, + }, + }, "status": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -346,6 +389,53 @@ func DataSourceIBMIsBackupPolicyJobs() *schema.Resource { Computed: true, Description: "The user-defined name for this snapshot.", }, + "remote": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the referenced resource is remote to thisaccount, and identifies the owning account.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this account.", + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + }, + }, + }, + "region": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this region.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The globally unique name for this region.", + }, + }, + }, + }, + }, + }, + }, "resource_type": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -512,8 +602,17 @@ func dataSourceBackupPolicyJobCollectionJobsToMap(jobsItem vpcv1.BackupPolicyJob sourceVolumeList = append(sourceVolumeList, sourceVolumeMap) jobsMap["source_instance"] = sourceVolumeList } + case "*vpcv1.BackupPolicyJobSourceShareReference": + { + jobSource := jobsItem.Source.(*vpcv1.BackupPolicyJobSourceShareReference) + sourceShareList := []map[string]interface{}{} + sourceShareMap := dataShareBackupPolicyJobSourceShareReferenceToMap(jobSource) + sourceShareList = append(sourceShareList, sourceShareMap) + jobsMap["source_share"] = sourceShareList + } } } + if jobsItem.Status != nil { jobsMap["status"] = jobsItem.Status } @@ -534,10 +633,38 @@ func dataSourceBackupPolicyJobCollectionJobsToMap(jobsItem vpcv1.BackupPolicyJob } jobsMap["target_snapshot"] = targetSnapshotList } - // log.Println("jobsItem") - // log.Println(jobsItem) return jobsMap } +func dataShareBackupPolicyJobSourceShareReferenceToMap(model *vpcv1.BackupPolicyJobSourceShareReference) map[string]interface{} { + modelMap := make(map[string]interface{}) + modelMap["crn"] = *model.CRN + if model.Deleted != nil { + deletedMap := ResourceIBMIsShareShareReferenceDeletedToMap(model.Deleted) + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + if model.Remote != nil { + remoteMap := ResourceIBMIsShareShareRemoteToMap(model.Remote) + modelMap["remote"] = []map[string]interface{}{remoteMap} + } + modelMap["resource_type"] = *model.ResourceType + return modelMap +} +func AccountReferenceToMap(model *vpcv1.AccountReference) map[string]interface{} { + modelMap := make(map[string]interface{}) + modelMap["id"] = *model.ID + modelMap["resource_type"] = *model.ResourceType + return modelMap +} + +func RegionReferenceToMap(model *vpcv1.RegionReference) map[string]interface{} { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["name"] = *model.Name + return modelMap +} func dataSourceBackupPolicyJobCollectionJobsBackupPolicyPlanToMap(backupPolicyPlanItem vpcv1.BackupPolicyPlanReference) (backupPolicyPlanMap map[string]interface{}) { backupPolicyPlanMap = map[string]interface{}{} @@ -674,9 +801,38 @@ func dataSourceBackupPolicyJobCollectionJobsStatusReasonsToMap(statusReasonsItem return statusReasonsMap } -func dataSourceBackupPolicyJobCollectionJobsTargetSnapshotToMap(targetSnapshotItem vpcv1.SnapshotReference) (targetSnapshotMap map[string]interface{}) { +func dataSourceBackupPolicyJobCollectionJobsTargetSnapshotRefToMap(targetSnapshotItem vpcv1.BackupPolicyTargetSnapshotSnapshotReference) (targetSnapshotMap map[string]interface{}) { targetSnapshotMap = map[string]interface{}{} + if targetSnapshotItem.CRN != nil { + targetSnapshotMap["crn"] = targetSnapshotItem.CRN + } + if targetSnapshotItem.Deleted != nil { + deletedList := []map[string]interface{}{} + deletedMap := dataSourceBackupPolicyJobCollectionTargetSnapshotDeletedToMap(*targetSnapshotItem.Deleted) + deletedList = append(deletedList, deletedMap) + targetSnapshotMap["deleted"] = deletedList + } + if targetSnapshotItem.Href != nil { + targetSnapshotMap["href"] = targetSnapshotItem.Href + } + if targetSnapshotItem.ID != nil { + targetSnapshotMap["id"] = targetSnapshotItem.ID + } + if targetSnapshotItem.Name != nil { + targetSnapshotMap["name"] = targetSnapshotItem.Name + } + if targetSnapshotItem.ResourceType != nil { + targetSnapshotMap["resource_type"] = targetSnapshotItem.ResourceType + } + if targetSnapshotItem.Remote != nil { + remoteMap := DataSourceIBMISRemoteAccountRegionToMap(targetSnapshotItem.Remote) + targetSnapshotMap["remote"] = []map[string]interface{}{remoteMap} + } + return targetSnapshotMap +} +func dataSourceBackupPolicyJobCollectionJobsTargetShareSnapshotRefToMap(targetSnapshotItem vpcv1.BackupPolicyTargetSnapshotShareSnapshotReference) (targetSnapshotMap map[string]interface{}) { + targetSnapshotMap = map[string]interface{}{} if targetSnapshotItem.CRN != nil { targetSnapshotMap["crn"] = targetSnapshotItem.CRN } @@ -701,6 +857,34 @@ func dataSourceBackupPolicyJobCollectionJobsTargetSnapshotToMap(targetSnapshotIt return targetSnapshotMap } +func DataSourceIBMISRemoteAccountRegionToMap(model *vpcv1.SnapshotRemote) map[string]interface{} { + modelMap := make(map[string]interface{}) + if model.Account != nil { + accountMap := AccountReferenceToMap(model.Account) + modelMap["account"] = []map[string]interface{}{accountMap} + } + if model.Region != nil { + regionMap := RegionReferenceToMap(model.Region) + modelMap["region"] = []map[string]interface{}{regionMap} + } + return modelMap +} +func dataSourceBackupPolicyJobCollectionJobsTargetSnapshotToMap(targetSnapshotItemIntf vpcv1.BackupPolicyTargetSnapshotIntf) (targetSnapshotMap map[string]interface{}) { + targetSnapshotMap = map[string]interface{}{} + switch reflect.TypeOf(targetSnapshotItemIntf).String() { + case "*vpcv1.BackupPolicyTargetSnapshotSnapshotReference": + { + targetSnapshotItem := targetSnapshotItemIntf.(*vpcv1.BackupPolicyTargetSnapshotSnapshotReference) + targetSnapshotMap = dataSourceBackupPolicyJobCollectionJobsTargetSnapshotRefToMap(*targetSnapshotItem) + } + case "*vpcv1.BackupPolicyTargetSnapshotShareSnapshotReference": + { + targetSnapshotItem := targetSnapshotItemIntf.(*vpcv1.BackupPolicyTargetSnapshotShareSnapshotReference) + targetSnapshotMap = dataSourceBackupPolicyJobCollectionJobsTargetShareSnapshotRefToMap(*targetSnapshotItem) + } + } + return targetSnapshotMap +} func dataSourceBackupPolicyJobCollectionTargetSnapshotDeletedToMap(deletedItem vpcv1.Deleted) (deletedMap map[string]interface{}) { deletedMap = map[string]interface{}{} diff --git a/ibm/service/vpc/data_source_ibm_is_share.go b/ibm/service/vpc/data_source_ibm_is_share.go index f27b5480bc..cd15ea7a22 100644 --- a/ibm/service/vpc/data_source_ibm_is_share.go +++ b/ibm/service/vpc/data_source_ibm_is_share.go @@ -532,6 +532,64 @@ func DataSourceIbmIsShare() *schema.Resource { }, }, }, + "snapshot_count": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The total number of snapshots for this share.", + }, + "snapshot_size": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The total size (in gigabytes) of snapshots used for this file share.", + }, + "source_snapshot": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The snapshot from which this share was cloned.This property will be present when the share was created from a snapshot.The resources supported by this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in thefuture.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The CRN for this share snapshot.", + }, + "deleted": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about deleted resources.", + }, + }, + }, + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this share snapshot.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this share snapshot.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this share snapshot. The name is unique across all snapshots for the file share.", + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + }, + }, + }, }, } } @@ -719,7 +777,24 @@ func dataSourceIbmIsShareRead(context context.Context, d *schema.ResourceData, m return diag.FromErr(fmt.Errorf("Error setting zone %s", err)) } } + if err = d.Set("snapshot_count", flex.IntValue(share.SnapshotCount)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting snapshot_count: %s", err), "(Data) ibm_is_share", "read", "set-snapshot_count").GetDiag() + } + if err = d.Set("snapshot_size", flex.IntValue(share.SnapshotSize)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting snapshot_size: %s", err), "(Data) ibm_is_share", "read", "set-snapshot_size").GetDiag() + } + sourceSnapshot := []map[string]interface{}{} + if share.SourceSnapshot != nil { + modelMap, err := DataSourceIBMIsShareShareSourceSnapshotToMap(share.SourceSnapshot) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_is_share", "read", "source_snapshot-to-map").GetDiag() + } + sourceSnapshot = append(sourceSnapshot, modelMap) + } + if err = d.Set("source_snapshot", sourceSnapshot); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting source_snapshot: %s", err), "(Data) ibm_is_share", "read", "set-source_snapshot").GetDiag() + } accesstags, err := flex.GetGlobalTagsUsingCRN(meta, *share.CRN, "", isAccessTagType) if err != nil { log.Printf( @@ -940,3 +1015,57 @@ func dataSourceShareSourceShareDeletedToMap(deletedItem vpcv1.Deleted) (deletedM return deletedMap } +func DataSourceIBMIsShareShareSourceSnapshotToMap(model vpcv1.ShareSourceSnapshotIntf) (map[string]interface{}, error) { + if _, ok := model.(*vpcv1.ShareSourceSnapshotShareSnapshotReference); ok { + return DataSourceIBMIsShareShareSourceSnapshotShareSnapshotReferenceToMap(model.(*vpcv1.ShareSourceSnapshotShareSnapshotReference)) + } else if _, ok := model.(*vpcv1.ShareSourceSnapshot); ok { + modelMap := make(map[string]interface{}) + model := model.(*vpcv1.ShareSourceSnapshot) + if model.CRN != nil { + modelMap["crn"] = *model.CRN + } + if model.Deleted != nil { + deletedMap, err := DataSourceIBMIsShareDeletedToMap(model.Deleted) + if err != nil { + return modelMap, err + } + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + if model.Href != nil { + modelMap["href"] = *model.Href + } + if model.ID != nil { + modelMap["id"] = *model.ID + } + if model.Name != nil { + modelMap["name"] = *model.Name + } + if model.ResourceType != nil { + modelMap["resource_type"] = *model.ResourceType + } + return modelMap, nil + } else { + return nil, fmt.Errorf("Unrecognized vpcv1.ShareSourceSnapshotIntf subtype encountered") + } +} +func DataSourceIBMIsShareShareSourceSnapshotShareSnapshotReferenceToMap(model *vpcv1.ShareSourceSnapshotShareSnapshotReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["crn"] = *model.CRN + if model.Deleted != nil { + deletedMap, err := DataSourceIBMIsShareDeletedToMap(model.Deleted) + if err != nil { + return modelMap, err + } + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + modelMap["resource_type"] = *model.ResourceType + return modelMap, nil +} +func DataSourceIBMIsShareDeletedToMap(model *vpcv1.Deleted) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["more_info"] = *model.MoreInfo + return modelMap, nil +} diff --git a/ibm/service/vpc/data_source_ibm_is_share_profile.go b/ibm/service/vpc/data_source_ibm_is_share_profile.go index 99a51fa726..9daeb3f9d5 100644 --- a/ibm/service/vpc/data_source_ibm_is_share_profile.go +++ b/ibm/service/vpc/data_source_ibm_is_share_profile.go @@ -203,9 +203,9 @@ func dataSourceShareProfileIopsToMap(iops vpcv1.ShareProfileIops) (iopsMap map[s } func dataSourceShareProfileCapacityToMap(capacity vpcv1.ShareProfileCapacity) (capacityMap map[string]interface{}) { capacityMap = map[string]interface{}{} - if capacity.Default != nil { - capacityMap["default"] = int(*capacity.Default) - } + // if capacity.Default != nil { + // capacityMap["default"] = int(*capacity.Default) + // } capacityMap["max"] = capacity.Max capacityMap["min"] = capacity.Min capacityMap["step"] = capacity.Step diff --git a/ibm/service/vpc/data_source_ibm_is_share_snapshot.go b/ibm/service/vpc/data_source_ibm_is_share_snapshot.go new file mode 100644 index 0000000000..67d88d726d --- /dev/null +++ b/ibm/service/vpc/data_source_ibm_is_share_snapshot.go @@ -0,0 +1,425 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.91.0-d9755c53-20240605-153412 + */ + +package vpc + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/vpc-go-sdk/vpcv1" +) + +func DataSourceIBMIsShareSnapshot() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMIsShareSnapshotRead, + + Schema: map[string]*schema.Schema{ + "share": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "The file share identifier.", + }, + "share_snapshot": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "The share snapshot identifier.", + }, + "backup_policy_plan": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, the backup policy plan which created this share snapshot.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "deleted": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about deleted resources.", + }, + }, + }, + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this backup policy plan.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this backup policy plan.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this backup policy plan. The name is unique across all plans in the backup policy.", + }, + "remote": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this region.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The globally unique name for this region.", + }, + }, + }, + }, + }, + }, + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + }, + }, + }, + "captured_at": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The date and time the data capture for this share snapshot was completed.If absent, this snapshot's data has not yet been captured.", + }, + "created_at": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The date and time that the share snapshot was created.", + }, + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The CRN for this share snapshot.", + }, + "fingerprint": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The fingerprint for this snapshot.", + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this share snapshot.", + }, + "lifecycle_state": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The lifecycle state of this share snapshot.", + }, + "minimum_size": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The minimum size of a share created from this snapshot. When a snapshot is created, this will be set to the size of the `source_share`.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this share snapshot. The name is unique across all snapshots for the file share.", + }, + "resource_group": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The resource group for this file share.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this resource group.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this resource group.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this resource group.", + }, + }, + }, + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The status of the share snapshot:- `available`: The share snapshot is available for use.- `failed`: The share snapshot is irrecoverably unusable.- `pending`: The share snapshot is being provisioned and is not yet usable.- `unusable`: The share snapshot is not currently usable (see `status_reasons`)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future.", + }, + "status_reasons": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The reasons for the current status (if any).", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "A reason code for the status:- `encryption_key_deleted`: File share snapshot is unusable because its `encryption_key` was deleted- `internal_error`: Internal error (contact IBM support)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future.", + }, + "message": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "An explanation of the status reason.", + }, + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about this status reason.", + }, + }, + }, + }, + "user_tags": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The [user tags](https://cloud.ibm.com/apidocs/tagging#types-of-tags) associated with this share snapshot.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "zone": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The zone this share snapshot resides in.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this zone.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The globally unique name for this zone.", + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMIsShareSnapshotRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + vpcClient, err := meta.(conns.ClientSession).VpcV1API() + if err != nil { + // Error is coming from SDK client, so it doesn't need to be discriminated. + tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_is_share_snapshot", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getShareSnapshotOptions := &vpcv1.GetShareSnapshotOptions{} + + getShareSnapshotOptions.SetShareID(d.Get("share").(string)) + getShareSnapshotOptions.SetID(d.Get("share_snapshot").(string)) + + shareSnapshot, _, err := vpcClient.GetShareSnapshotWithContext(context, getShareSnapshotOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetShareSnapshotWithContext failed: %s", err.Error()), "(Data) ibm_is_share_snapshot", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + d.SetId(fmt.Sprintf("%s/%s", *getShareSnapshotOptions.ShareID, *getShareSnapshotOptions.ID)) + + backupPolicyPlan := []map[string]interface{}{} + if shareSnapshot.BackupPolicyPlan != nil { + modelMap, err := DataSourceIBMIsShareSnapshotBackupPolicyPlanReferenceToMap(shareSnapshot.BackupPolicyPlan) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_is_share_snapshot", "read", "backup_policy_plan-to-map").GetDiag() + } + backupPolicyPlan = append(backupPolicyPlan, modelMap) + } + if err = d.Set("backup_policy_plan", backupPolicyPlan); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting backup_policy_plan: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-backup_policy_plan").GetDiag() + } + + if err = d.Set("captured_at", flex.DateTimeToString(shareSnapshot.CapturedAt)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting captured_at: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-captured_at").GetDiag() + } + + if err = d.Set("created_at", flex.DateTimeToString(shareSnapshot.CreatedAt)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting created_at: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-created_at").GetDiag() + } + + if err = d.Set("crn", shareSnapshot.CRN); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting crn: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-crn").GetDiag() + } + + if err = d.Set("fingerprint", shareSnapshot.Fingerprint); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting fingerprint: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-fingerprint").GetDiag() + } + + if err = d.Set("href", shareSnapshot.Href); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting href: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-href").GetDiag() + } + + if err = d.Set("lifecycle_state", shareSnapshot.LifecycleState); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting lifecycle_state: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-lifecycle_state").GetDiag() + } + + if err = d.Set("minimum_size", flex.IntValue(shareSnapshot.MinimumSize)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting minimum_size: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-minimum_size").GetDiag() + } + + if err = d.Set("name", shareSnapshot.Name); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting name: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-name").GetDiag() + } + + resourceGroup := []map[string]interface{}{} + if shareSnapshot.ResourceGroup != nil { + modelMap, err := DataSourceIBMIsShareSnapshotResourceGroupReferenceToMap(shareSnapshot.ResourceGroup) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_is_share_snapshot", "read", "resource_group-to-map").GetDiag() + } + resourceGroup = append(resourceGroup, modelMap) + } + if err = d.Set("resource_group", resourceGroup); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting resource_group: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-resource_group").GetDiag() + } + + if err = d.Set("resource_type", shareSnapshot.ResourceType); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting resource_type: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-resource_type").GetDiag() + } + + if err = d.Set("status", shareSnapshot.Status); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting status: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-status").GetDiag() + } + + statusReasons := []map[string]interface{}{} + if shareSnapshot.StatusReasons != nil { + for _, modelItem := range shareSnapshot.StatusReasons { + modelMap, err := DataSourceIBMIsShareSnapshotShareSnapshotStatusReasonToMap(&modelItem) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_is_share_snapshot", "read", "status_reasons-to-map").GetDiag() + } + statusReasons = append(statusReasons, modelMap) + } + } + if err = d.Set("status_reasons", statusReasons); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting status_reasons: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-status_reasons").GetDiag() + } + + zone := []map[string]interface{}{} + if shareSnapshot.Zone != nil { + modelMap, err := DataSourceIBMIsShareSnapshotZoneReferenceToMap(shareSnapshot.Zone) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_is_share_snapshot", "read", "zone-to-map").GetDiag() + } + zone = append(zone, modelMap) + } + if err = d.Set("zone", zone); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting zone: %s", err), "(Data) ibm_is_share_snapshot", "read", "set-zone").GetDiag() + } + + return nil +} + +func DataSourceIBMIsShareSnapshotBackupPolicyPlanReferenceToMap(model *vpcv1.BackupPolicyPlanReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Deleted != nil { + deletedMap, err := DataSourceIBMIsShareSnapshotDeletedToMap(model.Deleted) + if err != nil { + return modelMap, err + } + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + if model.Remote != nil { + remoteMap, err := DataSourceIBMIsShareSnapshotBackupPolicyPlanRemoteToMap(model.Remote) + if err != nil { + return modelMap, err + } + modelMap["remote"] = []map[string]interface{}{remoteMap} + } + modelMap["resource_type"] = *model.ResourceType + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotDeletedToMap(model *vpcv1.Deleted) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["more_info"] = *model.MoreInfo + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotBackupPolicyPlanRemoteToMap(model *vpcv1.BackupPolicyPlanRemote) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Region != nil { + regionMap, err := DataSourceIBMIsShareSnapshotRegionReferenceToMap(model.Region) + if err != nil { + return modelMap, err + } + modelMap["region"] = []map[string]interface{}{regionMap} + } + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotRegionReferenceToMap(model *vpcv1.RegionReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["name"] = *model.Name + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotResourceGroupReferenceToMap(model *vpcv1.ResourceGroupReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotShareSnapshotStatusReasonToMap(model *vpcv1.ShareSnapshotStatusReason) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["code"] = *model.Code + modelMap["message"] = *model.Message + if model.MoreInfo != nil { + modelMap["more_info"] = *model.MoreInfo + } + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotZoneReferenceToMap(model *vpcv1.ZoneReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["name"] = *model.Name + return modelMap, nil +} diff --git a/ibm/service/vpc/data_source_ibm_is_share_snapshot_test.go b/ibm/service/vpc/data_source_ibm_is_share_snapshot_test.go new file mode 100644 index 0000000000..94e1c41b0a --- /dev/null +++ b/ibm/service/vpc/data_source_ibm_is_share_snapshot_test.go @@ -0,0 +1,280 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.91.0-d9755c53-20240605-153412 + */ + +package vpc_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/vpc" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/vpc-go-sdk/vpcv1" + "github.com/stretchr/testify/assert" +) + +func TestAccIBMIsShareSnapshotDataSourceBasic(t *testing.T) { + shareSnapshotShareID := fmt.Sprintf("tf_share_id_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIsShareSnapshotDataSourceConfigBasic(shareSnapshotShareID), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "share"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "share_snapshot"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "created_at"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "crn"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "fingerprint"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "href"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "lifecycle_state"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "minimum_size"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "resource_type"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "status"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "status_reasons.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "zone.#"), + ), + }, + }, + }) +} + +func TestAccIBMIsShareSnapshotDataSourceAllArgs(t *testing.T) { + shareSnapshotShareID := fmt.Sprintf("tf_share_id_%d", acctest.RandIntRange(10, 100)) + shareSnapshotName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIsShareSnapshotDataSourceConfig(shareSnapshotShareID, shareSnapshotName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "share"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "share_snapshot"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "backup_policy_plan.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "captured_at"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "created_at"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "crn"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "fingerprint"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "href"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "lifecycle_state"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "minimum_size"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "resource_group.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "resource_type"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "status"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "status_reasons.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "status_reasons.0.code"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "status_reasons.0.message"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "status_reasons.0.more_info"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "user_tags.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshot.is_share_snapshot_instance", "zone.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMIsShareSnapshotDataSourceConfigBasic(shareSnapshotShareID string) string { + return fmt.Sprintf(` + resource "ibm_is_share_snapshot" "is_share_snapshot_instance" { + share = "%s" + } + + data "ibm_is_share_snapshot" "is_share_snapshot_instance" { + share = ibm_is_share_snapshot.is_share_snapshot_instance.share + share_snapshot = ibm_is_share_snapshot.is_share_snapshot_instance.share_snapshot + } + `, shareSnapshotShareID) +} + +func testAccCheckIBMIsShareSnapshotDataSourceConfig(shareSnapshotShareID string, shareSnapshotName string) string { + return fmt.Sprintf(` + resource "ibm_is_share_snapshot" "is_share_snapshot_instance" { + share = "%s" + name = "%s" + user_tags = "FIXME" + } + + data "ibm_is_share_snapshot" "is_share_snapshot_instance" { + share = ibm_is_share_snapshot.is_share_snapshot_instance.share + share_snapshot = ibm_is_share_snapshot.is_share_snapshot_instance.share_snapshot + } + `, shareSnapshotShareID, shareSnapshotName) +} + +func TestDataSourceIBMIsShareSnapshotBackupPolicyPlanReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + deletedModel := make(map[string]interface{}) + deletedModel["more_info"] = "https://cloud.ibm.com/apidocs/vpc#deleted-resources" + + regionReferenceModel := make(map[string]interface{}) + regionReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + regionReferenceModel["name"] = "us-south" + + backupPolicyPlanRemoteModel := make(map[string]interface{}) + backupPolicyPlanRemoteModel["region"] = []map[string]interface{}{regionReferenceModel} + + model := make(map[string]interface{}) + model["deleted"] = []map[string]interface{}{deletedModel} + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178" + model["id"] = "r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178" + model["name"] = "my-policy-plan" + model["remote"] = []map[string]interface{}{backupPolicyPlanRemoteModel} + model["resource_type"] = "backup_policy_plan" + + assert.Equal(t, result, model) + } + + deletedModel := new(vpcv1.Deleted) + deletedModel.MoreInfo = core.StringPtr("https://cloud.ibm.com/apidocs/vpc#deleted-resources") + + regionReferenceModel := new(vpcv1.RegionReference) + regionReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + regionReferenceModel.Name = core.StringPtr("us-south") + + backupPolicyPlanRemoteModel := new(vpcv1.BackupPolicyPlanRemote) + backupPolicyPlanRemoteModel.Region = regionReferenceModel + + model := new(vpcv1.BackupPolicyPlanReference) + model.Deleted = deletedModel + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178") + model.ID = core.StringPtr("r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178") + model.Name = core.StringPtr("my-policy-plan") + model.Remote = backupPolicyPlanRemoteModel + model.ResourceType = core.StringPtr("backup_policy_plan") + + result, err := vpc.DataSourceIBMIsShareSnapshotBackupPolicyPlanReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotDeletedToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["more_info"] = "https://cloud.ibm.com/apidocs/vpc#deleted-resources" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.Deleted) + model.MoreInfo = core.StringPtr("https://cloud.ibm.com/apidocs/vpc#deleted-resources") + + result, err := vpc.DataSourceIBMIsShareSnapshotDeletedToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotBackupPolicyPlanRemoteToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + regionReferenceModel := make(map[string]interface{}) + regionReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + regionReferenceModel["name"] = "us-south" + + model := make(map[string]interface{}) + model["region"] = []map[string]interface{}{regionReferenceModel} + + assert.Equal(t, result, model) + } + + regionReferenceModel := new(vpcv1.RegionReference) + regionReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + regionReferenceModel.Name = core.StringPtr("us-south") + + model := new(vpcv1.BackupPolicyPlanRemote) + model.Region = regionReferenceModel + + result, err := vpc.DataSourceIBMIsShareSnapshotBackupPolicyPlanRemoteToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotRegionReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + model["name"] = "us-south" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.RegionReference) + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + model.Name = core.StringPtr("us-south") + + result, err := vpc.DataSourceIBMIsShareSnapshotRegionReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotResourceGroupReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://resource-controller.cloud.ibm.com/v2/resource_groups/fee82deba12e4c0fb69c3b09d1f12345" + model["id"] = "fee82deba12e4c0fb69c3b09d1f12345" + model["name"] = "my-resource-group" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ResourceGroupReference) + model.Href = core.StringPtr("https://resource-controller.cloud.ibm.com/v2/resource_groups/fee82deba12e4c0fb69c3b09d1f12345") + model.ID = core.StringPtr("fee82deba12e4c0fb69c3b09d1f12345") + model.Name = core.StringPtr("my-resource-group") + + result, err := vpc.DataSourceIBMIsShareSnapshotResourceGroupReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotShareSnapshotStatusReasonToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["code"] = "encryption_key_deleted" + model["message"] = "testString" + model["more_info"] = "https://cloud.ibm.com/docs/key-protect?topic=key-protect-restore-keys" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ShareSnapshotStatusReason) + model.Code = core.StringPtr("encryption_key_deleted") + model.Message = core.StringPtr("testString") + model.MoreInfo = core.StringPtr("https://cloud.ibm.com/docs/key-protect?topic=key-protect-restore-keys") + + result, err := vpc.DataSourceIBMIsShareSnapshotShareSnapshotStatusReasonToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotZoneReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south/zones/us-south-1" + model["name"] = "us-south-1" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ZoneReference) + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south/zones/us-south-1") + model.Name = core.StringPtr("us-south-1") + + result, err := vpc.DataSourceIBMIsShareSnapshotZoneReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/vpc/data_source_ibm_is_share_snapshots.go b/ibm/service/vpc/data_source_ibm_is_share_snapshots.go new file mode 100644 index 0000000000..7596804b24 --- /dev/null +++ b/ibm/service/vpc/data_source_ibm_is_share_snapshots.go @@ -0,0 +1,441 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.91.0-d9755c53-20240605-153412 + */ + +package vpc + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/vpc-go-sdk/vpcv1" +) + +func DataSourceIBMIsShareSnapshots() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMIsShareSnapshotsRead, + + Schema: map[string]*schema.Schema{ + "share": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The file share identifier, or `-` to wildcard all accessible file shares.", + }, + "backup_policy_plan": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Filters the collection to backup policy jobs with a `backup_policy_plan.id` property matching the specified identifier.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Filters the collection to resources with a `name` property matching the exact specified name.", + }, + "snapshots": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "A page of share snapshots.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backup_policy_plan": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, the backup policy plan which created this share snapshot.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "deleted": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about deleted resources.", + }, + }, + }, + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this backup policy plan.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this backup policy plan.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this backup policy plan. The name is unique across all plans in the backup policy.", + }, + "remote": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this region.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The globally unique name for this region.", + }, + }, + }, + }, + }, + }, + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + }, + }, + }, + "captured_at": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The date and time the data capture for this share snapshot was completed.If absent, this snapshot's data has not yet been captured.", + }, + "created_at": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The date and time that the share snapshot was created.", + }, + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The CRN for this share snapshot.", + }, + "fingerprint": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The fingerprint for this snapshot.", + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this share snapshot.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this share snapshot.", + }, + "lifecycle_state": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The lifecycle state of this share snapshot.", + }, + "minimum_size": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The minimum size of a share created from this snapshot. When a snapshot is created, this will be set to the size of the `source_share`.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this share snapshot. The name is unique across all snapshots for the file share.", + }, + "resource_group": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The resource group for this file share.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this resource group.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this resource group.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this resource group.", + }, + }, + }, + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The status of the share snapshot:- `available`: The share snapshot is available for use.- `failed`: The share snapshot is irrecoverably unusable.- `pending`: The share snapshot is being provisioned and is not yet usable.- `unusable`: The share snapshot is not currently usable (see `status_reasons`)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future.", + }, + "status_reasons": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The reasons for the current status (if any).", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "A reason code for the status:- `encryption_key_deleted`: File share snapshot is unusable because its `encryption_key` was deleted- `internal_error`: Internal error (contact IBM support)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future.", + }, + "message": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "An explanation of the status reason.", + }, + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about this status reason.", + }, + }, + }, + }, + "user_tags": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The [user tags](https://cloud.ibm.com/apidocs/tagging#types-of-tags) associated with this share snapshot.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "zone": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The zone this share snapshot resides in.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this zone.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The globally unique name for this zone.", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMIsShareSnapshotsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + vpcClient, err := meta.(conns.ClientSession).VpcV1API() + if err != nil { + tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_is_share_snapshots", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + listShareSnapshotsOptions := &vpcv1.ListShareSnapshotsOptions{} + + if shareIntf, ok := d.GetOk("share"); ok { + listShareSnapshotsOptions.SetShareID(shareIntf.(string)) + } else { + listShareSnapshotsOptions.SetShareID("-") + } + + if _, ok := d.GetOk("backup_policy_plan"); ok { + listShareSnapshotsOptions.SetBackupPolicyPlanID(d.Get("backup_policy_plan").(string)) + } + if _, ok := d.GetOk("name"); ok { + listShareSnapshotsOptions.SetName(d.Get("name").(string)) + } + + var pager *vpcv1.ShareSnapshotsPager + pager, err = vpcClient.NewShareSnapshotsPager(listShareSnapshotsOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_is_share_snapshots", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + allItems, err := pager.GetAll() + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("ShareSnapshotsPager.GetAll() failed %s", err), "(Data) ibm_is_share_snapshots", "read") + log.Printf("[DEBUG] %s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMIsShareSnapshotsID(d)) + + mapSlice := []map[string]interface{}{} + for _, modelItem := range allItems { + modelMap, err := DataSourceIBMIsShareSnapshotsShareSnapshotToMap(&modelItem) + if err != nil { + tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_is_share_snapshots", "read") + return tfErr.GetDiag() + } + mapSlice = append(mapSlice, modelMap) + } + + if err = d.Set("snapshots", mapSlice); err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting snapshots %s", err), "(Data) ibm_is_share_snapshots", "read") + return tfErr.GetDiag() + } + + return nil +} + +// dataSourceIBMIsShareSnapshotsID returns a reasonable ID for the list. +func dataSourceIBMIsShareSnapshotsID(d *schema.ResourceData) string { + return time.Now().UTC().String() +} + +func DataSourceIBMIsShareSnapshotsShareSnapshotToMap(model *vpcv1.ShareSnapshot) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.BackupPolicyPlan != nil { + backupPolicyPlanMap, err := DataSourceIBMIsShareSnapshotsBackupPolicyPlanReferenceToMap(model.BackupPolicyPlan) + if err != nil { + return modelMap, err + } + modelMap["backup_policy_plan"] = []map[string]interface{}{backupPolicyPlanMap} + } + if model.CapturedAt != nil { + modelMap["captured_at"] = model.CapturedAt.String() + } + modelMap["created_at"] = model.CreatedAt.String() + modelMap["crn"] = *model.CRN + modelMap["fingerprint"] = *model.Fingerprint + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["lifecycle_state"] = *model.LifecycleState + modelMap["minimum_size"] = flex.IntValue(model.MinimumSize) + modelMap["name"] = *model.Name + if model.ResourceGroup != nil { + resourceGroupMap, err := DataSourceIBMIsShareSnapshotsResourceGroupReferenceToMap(model.ResourceGroup) + if err != nil { + return modelMap, err + } + modelMap["resource_group"] = []map[string]interface{}{resourceGroupMap} + } + modelMap["resource_type"] = *model.ResourceType + modelMap["status"] = *model.Status + statusReasons := []map[string]interface{}{} + for _, statusReasonsItem := range model.StatusReasons { + statusReasonsItemMap, err := DataSourceIBMIsShareSnapshotsShareSnapshotStatusReasonToMap(&statusReasonsItem) + if err != nil { + return modelMap, err + } + statusReasons = append(statusReasons, statusReasonsItemMap) + } + modelMap["status_reasons"] = statusReasons + if model.UserTags != nil { + modelMap["user_tags"] = model.UserTags + } + zoneMap, err := DataSourceIBMIsShareSnapshotsZoneReferenceToMap(model.Zone) + if err != nil { + return modelMap, err + } + modelMap["zone"] = []map[string]interface{}{zoneMap} + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotsBackupPolicyPlanReferenceToMap(model *vpcv1.BackupPolicyPlanReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Deleted != nil { + deletedMap, err := DataSourceIBMIsShareSnapshotsDeletedToMap(model.Deleted) + if err != nil { + return modelMap, err + } + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + if model.Remote != nil { + remoteMap, err := DataSourceIBMIsShareSnapshotsBackupPolicyPlanRemoteToMap(model.Remote) + if err != nil { + return modelMap, err + } + modelMap["remote"] = []map[string]interface{}{remoteMap} + } + modelMap["resource_type"] = *model.ResourceType + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotsDeletedToMap(model *vpcv1.Deleted) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["more_info"] = *model.MoreInfo + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotsBackupPolicyPlanRemoteToMap(model *vpcv1.BackupPolicyPlanRemote) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Region != nil { + regionMap, err := DataSourceIBMIsShareSnapshotsRegionReferenceToMap(model.Region) + if err != nil { + return modelMap, err + } + modelMap["region"] = []map[string]interface{}{regionMap} + } + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotsRegionReferenceToMap(model *vpcv1.RegionReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["name"] = *model.Name + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotsResourceGroupReferenceToMap(model *vpcv1.ResourceGroupReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotsShareSnapshotStatusReasonToMap(model *vpcv1.ShareSnapshotStatusReason) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["code"] = *model.Code + modelMap["message"] = *model.Message + if model.MoreInfo != nil { + modelMap["more_info"] = *model.MoreInfo + } + return modelMap, nil +} + +func DataSourceIBMIsShareSnapshotsZoneReferenceToMap(model *vpcv1.ZoneReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["name"] = *model.Name + return modelMap, nil +} diff --git a/ibm/service/vpc/data_source_ibm_is_share_snapshots_test.go b/ibm/service/vpc/data_source_ibm_is_share_snapshots_test.go new file mode 100644 index 0000000000..766463f131 --- /dev/null +++ b/ibm/service/vpc/data_source_ibm_is_share_snapshots_test.go @@ -0,0 +1,379 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.91.0-d9755c53-20240605-153412 + */ + +package vpc_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/vpc" + . "github.com/IBM-Cloud/terraform-provider-ibm/ibm/unittest" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/vpc-go-sdk/vpcv1" + "github.com/stretchr/testify/assert" +) + +func TestAccIBMIsShareSnapshotsDataSourceBasic(t *testing.T) { + shareSnapshotShareID := fmt.Sprintf("tf_share_id_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIsShareSnapshotsDataSourceConfigBasic(shareSnapshotShareID), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "share_id"), + ), + }, + }, + }) +} + +func TestAccIBMIsShareSnapshotsDataSourceAllArgs(t *testing.T) { + shareSnapshotShareID := fmt.Sprintf("tf_share_id_%d", acctest.RandIntRange(10, 100)) + shareSnapshotName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIsShareSnapshotsDataSourceConfig(shareSnapshotShareID, shareSnapshotName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "share_id"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "backup_policy_plan_id"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "name"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "sort"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.captured_at"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.created_at"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.crn"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.fingerprint"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.href"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.id"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.lifecycle_state"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.minimum_size"), + resource.TestCheckResourceAttr("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.name", shareSnapshotName), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.resource_type"), + resource.TestCheckResourceAttrSet("data.ibm_is_share_snapshots.is_share_snapshots_instance", "snapshots.0.status"), + ), + }, + }, + }) +} + +func testAccCheckIBMIsShareSnapshotsDataSourceConfigBasic(shareSnapshotShareID string) string { + return fmt.Sprintf(` + resource "ibm_is_share_snapshot" "is_share_snapshot_instance" { + share_id = "%s" + } + + data "ibm_is_share_snapshots" "is_share_snapshots_instance" { + share_id = ibm_is_share_snapshot.is_share_snapshot_instance.share_id + backup_policy_plan_id = "backup_policy_plan_id" + name = ibm_is_share_snapshot.is_share_snapshot_instance.name + sort = "name" + } + `, shareSnapshotShareID) +} + +func testAccCheckIBMIsShareSnapshotsDataSourceConfig(shareSnapshotShareID string, shareSnapshotName string) string { + return fmt.Sprintf(` + resource "ibm_is_share_snapshot" "is_share_snapshot_instance" { + share_id = "%s" + name = "%s" + user_tags = "FIXME" + } + + data "ibm_is_share_snapshots" "is_share_snapshots_instance" { + share_id = ibm_is_share_snapshot.is_share_snapshot_instance.share_id + backup_policy_plan_id = "backup_policy_plan_id" + name = ibm_is_share_snapshot.is_share_snapshot_instance.name + sort = "name" + } + `, shareSnapshotShareID, shareSnapshotName) +} + +func TestDataSourceIBMIsShareSnapshotsShareSnapshotToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + deletedModel := make(map[string]interface{}) + deletedModel["more_info"] = "https://cloud.ibm.com/apidocs/vpc#deleted-resources" + + regionReferenceModel := make(map[string]interface{}) + regionReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + regionReferenceModel["name"] = "us-south" + + backupPolicyPlanRemoteModel := make(map[string]interface{}) + backupPolicyPlanRemoteModel["region"] = []map[string]interface{}{regionReferenceModel} + + backupPolicyPlanReferenceModel := make(map[string]interface{}) + backupPolicyPlanReferenceModel["deleted"] = []map[string]interface{}{deletedModel} + backupPolicyPlanReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178" + backupPolicyPlanReferenceModel["id"] = "r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178" + backupPolicyPlanReferenceModel["name"] = "my-policy-plan" + backupPolicyPlanReferenceModel["remote"] = []map[string]interface{}{backupPolicyPlanRemoteModel} + backupPolicyPlanReferenceModel["resource_type"] = "backup_policy_plan" + + resourceGroupReferenceModel := make(map[string]interface{}) + resourceGroupReferenceModel["href"] = "https://resource-controller.cloud.ibm.com/v2/resource_groups/fee82deba12e4c0fb69c3b09d1f12345" + resourceGroupReferenceModel["id"] = "fee82deba12e4c0fb69c3b09d1f12345" + resourceGroupReferenceModel["name"] = "Default" + + shareSnapshotStatusReasonModel := make(map[string]interface{}) + shareSnapshotStatusReasonModel["code"] = "encryption_key_deleted" + shareSnapshotStatusReasonModel["message"] = "testString" + shareSnapshotStatusReasonModel["more_info"] = "https://cloud.ibm.com/docs/key-protect?topic=key-protect-restore-keys" + + zoneReferenceModel := make(map[string]interface{}) + zoneReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south/zones/us-south-1" + zoneReferenceModel["name"] = "us-south-1" + + model := make(map[string]interface{}) + model["backup_policy_plan"] = []map[string]interface{}{backupPolicyPlanReferenceModel} + model["captured_at"] = "2019-01-01T12:00:00.000Z" + model["created_at"] = "2019-01-01T12:00:00.000Z" + model["crn"] = "crn:v1:bluemix:public:is:us-south:a/aa2432b1fa4d4ace891e9b80fc104e34::share-snapshot:r006-0fe9e5d8-0a4d-4818-96ec-e99708644a58/r006-e13ee54f-baa4-40d3-b35c-b9ec163972b4" + model["fingerprint"] = "7abc3aef-c2bc-4f65-a296-2928e534d498" + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/shares/r006-0fe9e5d8-0a4d-4818-96ec-e99708644a58/snapshots/r006-e13ee54f-baa4-40d3-b35c-b9ec163972b4" + model["id"] = "r006-e13ee54f-baa4-40d3-b35c-b9ec163972b4" + model["lifecycle_state"] = "stable" + model["minimum_size"] = int(10) + model["name"] = "my-share-snapshot" + model["resource_group"] = []map[string]interface{}{resourceGroupReferenceModel} + model["resource_type"] = "share_snapshot" + model["status"] = "available" + model["status_reasons"] = []map[string]interface{}{shareSnapshotStatusReasonModel} + model["user_tags"] = []string{"testString"} + model["zone"] = []map[string]interface{}{zoneReferenceModel} + + assert.Equal(t, result, model) + } + + deletedModel := new(vpcv1.Deleted) + deletedModel.MoreInfo = core.StringPtr("https://cloud.ibm.com/apidocs/vpc#deleted-resources") + + regionReferenceModel := new(vpcv1.RegionReference) + regionReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + regionReferenceModel.Name = core.StringPtr("us-south") + + backupPolicyPlanRemoteModel := new(vpcv1.BackupPolicyPlanRemote) + backupPolicyPlanRemoteModel.Region = regionReferenceModel + + backupPolicyPlanReferenceModel := new(vpcv1.BackupPolicyPlanReference) + backupPolicyPlanReferenceModel.Deleted = deletedModel + backupPolicyPlanReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178") + backupPolicyPlanReferenceModel.ID = core.StringPtr("r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178") + backupPolicyPlanReferenceModel.Name = core.StringPtr("my-policy-plan") + backupPolicyPlanReferenceModel.Remote = backupPolicyPlanRemoteModel + backupPolicyPlanReferenceModel.ResourceType = core.StringPtr("backup_policy_plan") + + resourceGroupReferenceModel := new(vpcv1.ResourceGroupReference) + resourceGroupReferenceModel.Href = core.StringPtr("https://resource-controller.cloud.ibm.com/v2/resource_groups/fee82deba12e4c0fb69c3b09d1f12345") + resourceGroupReferenceModel.ID = core.StringPtr("fee82deba12e4c0fb69c3b09d1f12345") + resourceGroupReferenceModel.Name = core.StringPtr("Default") + + shareSnapshotStatusReasonModel := new(vpcv1.ShareSnapshotStatusReason) + shareSnapshotStatusReasonModel.Code = core.StringPtr("encryption_key_deleted") + shareSnapshotStatusReasonModel.Message = core.StringPtr("testString") + shareSnapshotStatusReasonModel.MoreInfo = core.StringPtr("https://cloud.ibm.com/docs/key-protect?topic=key-protect-restore-keys") + + zoneReferenceModel := new(vpcv1.ZoneReference) + zoneReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south/zones/us-south-1") + zoneReferenceModel.Name = core.StringPtr("us-south-1") + + model := new(vpcv1.ShareSnapshot) + model.BackupPolicyPlan = backupPolicyPlanReferenceModel + model.CapturedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + model.CreatedAt = CreateMockDateTime("2019-01-01T12:00:00.000Z") + model.CRN = core.StringPtr("crn:v1:bluemix:public:is:us-south:a/aa2432b1fa4d4ace891e9b80fc104e34::share-snapshot:r006-0fe9e5d8-0a4d-4818-96ec-e99708644a58/r006-e13ee54f-baa4-40d3-b35c-b9ec163972b4") + model.Fingerprint = core.StringPtr("7abc3aef-c2bc-4f65-a296-2928e534d498") + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/shares/r006-0fe9e5d8-0a4d-4818-96ec-e99708644a58/snapshots/r006-e13ee54f-baa4-40d3-b35c-b9ec163972b4") + model.ID = core.StringPtr("r006-e13ee54f-baa4-40d3-b35c-b9ec163972b4") + model.LifecycleState = core.StringPtr("stable") + model.MinimumSize = core.Int64Ptr(int64(10)) + model.Name = core.StringPtr("my-share-snapshot") + model.ResourceGroup = resourceGroupReferenceModel + model.ResourceType = core.StringPtr("share_snapshot") + model.Status = core.StringPtr("available") + model.StatusReasons = []vpcv1.ShareSnapshotStatusReason{*shareSnapshotStatusReasonModel} + model.UserTags = []string{"testString"} + model.Zone = zoneReferenceModel + + result, err := vpc.DataSourceIBMIsShareSnapshotsShareSnapshotToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotsBackupPolicyPlanReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + deletedModel := make(map[string]interface{}) + deletedModel["more_info"] = "https://cloud.ibm.com/apidocs/vpc#deleted-resources" + + regionReferenceModel := make(map[string]interface{}) + regionReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + regionReferenceModel["name"] = "us-south" + + backupPolicyPlanRemoteModel := make(map[string]interface{}) + backupPolicyPlanRemoteModel["region"] = []map[string]interface{}{regionReferenceModel} + + model := make(map[string]interface{}) + model["deleted"] = []map[string]interface{}{deletedModel} + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178" + model["id"] = "r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178" + model["name"] = "my-policy-plan" + model["remote"] = []map[string]interface{}{backupPolicyPlanRemoteModel} + model["resource_type"] = "backup_policy_plan" + + assert.Equal(t, result, model) + } + + deletedModel := new(vpcv1.Deleted) + deletedModel.MoreInfo = core.StringPtr("https://cloud.ibm.com/apidocs/vpc#deleted-resources") + + regionReferenceModel := new(vpcv1.RegionReference) + regionReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + regionReferenceModel.Name = core.StringPtr("us-south") + + backupPolicyPlanRemoteModel := new(vpcv1.BackupPolicyPlanRemote) + backupPolicyPlanRemoteModel.Region = regionReferenceModel + + model := new(vpcv1.BackupPolicyPlanReference) + model.Deleted = deletedModel + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178") + model.ID = core.StringPtr("r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178") + model.Name = core.StringPtr("my-policy-plan") + model.Remote = backupPolicyPlanRemoteModel + model.ResourceType = core.StringPtr("backup_policy_plan") + + result, err := vpc.DataSourceIBMIsShareSnapshotsBackupPolicyPlanReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotsDeletedToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["more_info"] = "https://cloud.ibm.com/apidocs/vpc#deleted-resources" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.Deleted) + model.MoreInfo = core.StringPtr("https://cloud.ibm.com/apidocs/vpc#deleted-resources") + + result, err := vpc.DataSourceIBMIsShareSnapshotsDeletedToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotsBackupPolicyPlanRemoteToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + regionReferenceModel := make(map[string]interface{}) + regionReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + regionReferenceModel["name"] = "us-south" + + model := make(map[string]interface{}) + model["region"] = []map[string]interface{}{regionReferenceModel} + + assert.Equal(t, result, model) + } + + regionReferenceModel := new(vpcv1.RegionReference) + regionReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + regionReferenceModel.Name = core.StringPtr("us-south") + + model := new(vpcv1.BackupPolicyPlanRemote) + model.Region = regionReferenceModel + + result, err := vpc.DataSourceIBMIsShareSnapshotsBackupPolicyPlanRemoteToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotsRegionReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + model["name"] = "us-south" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.RegionReference) + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + model.Name = core.StringPtr("us-south") + + result, err := vpc.DataSourceIBMIsShareSnapshotsRegionReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotsResourceGroupReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://resource-controller.cloud.ibm.com/v2/resource_groups/fee82deba12e4c0fb69c3b09d1f12345" + model["id"] = "fee82deba12e4c0fb69c3b09d1f12345" + model["name"] = "my-resource-group" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ResourceGroupReference) + model.Href = core.StringPtr("https://resource-controller.cloud.ibm.com/v2/resource_groups/fee82deba12e4c0fb69c3b09d1f12345") + model.ID = core.StringPtr("fee82deba12e4c0fb69c3b09d1f12345") + model.Name = core.StringPtr("my-resource-group") + + result, err := vpc.DataSourceIBMIsShareSnapshotsResourceGroupReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotsShareSnapshotStatusReasonToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["code"] = "encryption_key_deleted" + model["message"] = "testString" + model["more_info"] = "https://cloud.ibm.com/docs/key-protect?topic=key-protect-restore-keys" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ShareSnapshotStatusReason) + model.Code = core.StringPtr("encryption_key_deleted") + model.Message = core.StringPtr("testString") + model.MoreInfo = core.StringPtr("https://cloud.ibm.com/docs/key-protect?topic=key-protect-restore-keys") + + result, err := vpc.DataSourceIBMIsShareSnapshotsShareSnapshotStatusReasonToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMIsShareSnapshotsZoneReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south/zones/us-south-1" + model["name"] = "us-south-1" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ZoneReference) + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south/zones/us-south-1") + model.Name = core.StringPtr("us-south-1") + + result, err := vpc.DataSourceIBMIsShareSnapshotsZoneReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/vpc/data_source_ibm_is_shares.go b/ibm/service/vpc/data_source_ibm_is_shares.go index 0ee814a270..58ac287351 100644 --- a/ibm/service/vpc/data_source_ibm_is_shares.go +++ b/ibm/service/vpc/data_source_ibm_is_shares.go @@ -503,6 +503,64 @@ func DataSourceIbmIsShares() *schema.Resource { }, }, }, + "snapshot_count": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The total number of snapshots for this share.", + }, + "snapshot_size": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The total size (in gigabytes) of snapshots used for this file share.", + }, + "source_snapshot": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The snapshot from which this share was cloned.This property will be present when the share was created from a snapshot.The resources supported by this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in thefuture.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The CRN for this share snapshot.", + }, + "deleted": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about deleted resources.", + }, + }, + }, + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this share snapshot.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this share snapshot.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this share snapshot. The name is unique across all snapshots for the file share.", + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + }, + }, + }, }, }, }, @@ -561,9 +619,13 @@ func dataSourceIbmIsSharesRead(context context.Context, d *schema.ResourceData, d.SetId(dataSourceIbmIsSharesID(d)) if allrecs != nil { - err = d.Set("shares", dataSourceShareCollectionFlattenShares(meta, allrecs)) + shares, err := dataSourceShareCollectionFlattenShares(meta, allrecs) if err != nil { - return diag.FromErr(fmt.Errorf("Error setting shares %s", err)) + return err + } + errSettingShares := d.Set("shares", shares) + if errSettingShares != nil { + return diag.FromErr(fmt.Errorf("Error setting shares %s", errSettingShares)) } } if err = d.Set("total_count", totalCount); err != nil { @@ -578,15 +640,19 @@ func dataSourceIbmIsSharesID(d *schema.ResourceData) string { return time.Now().UTC().String() } -func dataSourceShareCollectionFlattenShares(meta interface{}, result []vpcv1.Share) (shares []map[string]interface{}) { +func dataSourceShareCollectionFlattenShares(meta interface{}, result []vpcv1.Share) (shares []map[string]interface{}, diag diag.Diagnostics) { for _, sharesItem := range result { - shares = append(shares, dataSourceShareCollectionSharesToMap(meta, sharesItem)) + shareMap, err := dataSourceShareCollectionSharesToMap(meta, sharesItem) + if err != nil { + return nil, err + } + shares = append(shares, shareMap) } - return shares + return shares, nil } -func dataSourceShareCollectionSharesToMap(meta interface{}, sharesItem vpcv1.Share) (sharesMap map[string]interface{}) { +func dataSourceShareCollectionSharesToMap(meta interface{}, sharesItem vpcv1.Share) (sharesMap map[string]interface{}, diag diag.Diagnostics) { sharesMap = map[string]interface{}{} if sharesItem.CreatedAt != nil { @@ -688,7 +754,21 @@ func dataSourceShareCollectionSharesToMap(meta interface{}, sharesItem vpcv1.Sha if sharesItem.Zone != nil { sharesMap["zone"] = *sharesItem.Zone.Name } - + if sharesItem.SnapshotCount != nil { + sharesMap["snapshot_count"] = flex.IntValue(sharesItem.SnapshotCount) + } + if sharesItem.SnapshotSize != nil { + sharesMap["snapshot_size"] = flex.IntValue(sharesItem.SnapshotSize) + } + sourceSnapshot := []map[string]interface{}{} + if sharesItem.SourceSnapshot != nil { + modelMap, err := DataSourceIBMIsShareShareSourceSnapshotToMap(sharesItem.SourceSnapshot) + if err != nil { + return nil, flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_is_share", "read", "source_snapshot-to-map").GetDiag() + } + sourceSnapshot = append(sourceSnapshot, modelMap) + } + sharesMap["source_snapshot"] = sourceSnapshot accesstags, err := flex.GetGlobalTagsUsingCRN(meta, *sharesItem.CRN, "", isAccessTagType) if err != nil { log.Printf( @@ -699,7 +779,7 @@ func dataSourceShareCollectionSharesToMap(meta interface{}, sharesItem vpcv1.Sha sharesMap[isFileShareTags] = sharesItem.UserTags } sharesMap[isFileShareAccessTags] = accesstags - return sharesMap + return sharesMap, nil } func dataSourceShareCollectionSharesTargetsToMap(targetsItem vpcv1.ShareMountTargetReference) (targetsMap map[string]interface{}) { diff --git a/ibm/service/vpc/resource_ibm_is_backup_policy.go b/ibm/service/vpc/resource_ibm_is_backup_policy.go index 30aaa3acd1..9214192e1a 100644 --- a/ibm/service/vpc/resource_ibm_is_backup_policy.go +++ b/ibm/service/vpc/resource_ibm_is_backup_policy.go @@ -205,7 +205,7 @@ func ResourceIBMIsBackupPolicyValidator() *validate.ResourceValidator { ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, Type: validate.TypeString, Required: true, - AllowedValues: "instance, volume", + AllowedValues: "instance, volume, share", }, ) resourceValidator := validate.ResourceValidator{ResourceName: "ibm_is_backup_policy", Schema: validateSchema} diff --git a/ibm/service/vpc/resource_ibm_is_share.go b/ibm/service/vpc/resource_ibm_is_share.go index 219185463c..18269e71e3 100644 --- a/ibm/service/vpc/resource_ibm_is_share.go +++ b/ibm/service/vpc/resource_ibm_is_share.go @@ -576,7 +576,7 @@ func ResourceIbmIsShare() *schema.Resource { Optional: true, ForceNew: true, Computed: true, - ConflictsWith: []string{"replica_share", "size", "source_share_crn", "origin_share.0.id", "origin_share.0.crn"}, + ConflictsWith: []string{"replica_share", "size", "source_share_crn", "origin_share.0.id", "origin_share.0.crn", "source_snapshot.0.id", "source_snapshot.0.crn"}, RequiredWith: []string{"replication_cron_spec"}, Description: "The ID of the source file share for this replica file share. The specified file share must not already have a replica, and must not be a replica.", }, @@ -585,16 +585,81 @@ func ResourceIbmIsShare() *schema.Resource { Optional: true, ForceNew: true, Computed: true, - ConflictsWith: []string{"replica_share", "size", "source_share", "origin_share.0.id", "origin_share.0.crn"}, + ConflictsWith: []string{"replica_share", "size", "source_share", "origin_share.0.id", "origin_share.0.crn", "source_snapshot.0.id", "source_snapshot.0.crn"}, RequiredWith: []string{"replication_cron_spec"}, Description: "The CRN of the source file share for this replica file share. The specified file share must not already have a replica, and must not be a replica.", }, + "source_snapshot": &schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + ConflictsWith: []string{"zone", "source_share", "source_share_crn", "origin_share.0.id", "origin_share.0.crn"}, + Description: "The snapshot from which this share was cloned.This property will be present when the share was created from a snapshot.The resources supported by this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in thefuture.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "crn": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"source_snapshot.0.id"}, + Description: "The CRN for this share snapshot.", + }, + "deleted": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about deleted resources.", + }, + }, + }, + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this share snapshot.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"source_snapshot.0.crn"}, + Description: "The unique identifier for this share snapshot.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this share snapshot. The name is unique across all snapshots for the file share.", + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + }, + }, + }, + "snapshot_count": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The total number of snapshots for this share.", + }, + "snapshot_size": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The total size (in gigabytes) of snapshots used for this file share.", + }, "origin_share": &schema.Schema{ Type: schema.TypeList, MaxItems: 1, Optional: true, Computed: true, - ConflictsWith: []string{"replica_share", "size", "source_share", "source_share_crn"}, + ConflictsWith: []string{"replica_share", "size", "source_share", "source_share_crn", "source_snapshot.0.id", "source_snapshot.0.crn"}, Description: "The origin share this accessor share is referring to.This property will be present when the `accessor_binding_role` is `accessor`.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -1005,10 +1070,26 @@ func resourceIbmIsShareCreate(context context.Context, d *schema.ResourceData, m } sharePrototype.EncryptionKey = encryptionKeyIdentity } - if sizeIntf, ok := d.GetOk("size"); ok { - - size := int64(sizeIntf.(int)) - sharePrototype.Size = &size + if resgrp, ok := d.GetOk("resource_group"); ok { + resgrpstr := resgrp.(string) + resourceGroup := &vpcv1.ResourceGroupIdentity{ + ID: &resgrpstr, + } + sharePrototype.ResourceGroup = resourceGroup + } + _, snapshotOk := d.GetOk("source_snapshot") + _, sizeOk := d.GetOk("size") + if snapshotOk || sizeOk { + if sourceSnapshotIntf, snapOk := d.GetOk("source_snapshot"); snapOk { + if len(sourceSnapshotIntf.([]interface{})) > 0 { + SourceSnapshotModel := ResourceIBMIsShareMapToShareSourceSnapshotPrototype(sourceSnapshotIntf.([]interface{})[0].(map[string]interface{})) + sharePrototype.SourceSnapshot = SourceSnapshotModel + } + } + if sizeIntf, sizeIntfOk := d.GetOk("size"); sizeIntfOk { + size := int64(sizeIntf.(int)) + sharePrototype.Size = &size + } initial_owner := &vpcv1.ShareInitialOwner{} if initialOwnerIntf, ok := d.GetOk("initial_owner"); ok { @@ -1022,13 +1103,7 @@ func resourceIbmIsShareCreate(context context.Context, d *schema.ResourceData, m initial_owner.Uid = &initialOwnerUID } } - if resgrp, ok := d.GetOk("resource_group"); ok { - resgrpstr := resgrp.(string) - resourceGroup := &vpcv1.ResourceGroupIdentity{ - ID: &resgrpstr, - } - sharePrototype.ResourceGroup = resourceGroup - } + if replicaShareIntf, ok := d.GetOk("replica_share"); ok { replicaShareMap := replicaShareIntf.([]interface{})[0].(map[string]interface{}) replicaShare := &vpcv1.SharePrototypeShareContext{} @@ -1108,14 +1183,13 @@ func resourceIbmIsShareCreate(context context.Context, d *schema.ResourceData, m } replicationCronSpec := d.Get("replication_cron_spec").(string) sharePrototype.ReplicationCronSpec = &replicationCronSpec - } else { + } else if _, originShareOk := d.GetOk("origin_share"); originShareOk { originShare := d.Get("origin_share") if len(originShare.([]interface{})) > 0 { OriginShareModel := ResourceIBMIsShareMapToShareIdentity(originShare.([]interface{})[0].(map[string]interface{})) sharePrototype.OriginShare = OriginShareModel } } - if iopsIntf, ok := d.GetOk("iops"); ok { iops := int64(iopsIntf.(int)) sharePrototype.Iops = &iops @@ -1405,7 +1479,24 @@ func resourceIbmIsShareRead(context context.Context, d *schema.ResourceData, met if err = d.Set("resource_type", share.ResourceType); err != nil { return diag.FromErr(fmt.Errorf("Error setting resource_type: %s", err)) } - + if err = d.Set("snapshot_count", flex.IntValue(share.SnapshotCount)); err != nil { + err = fmt.Errorf("Error setting snapshot_count: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share", "read", "set-snapshot_count").GetDiag() + } + if err = d.Set("snapshot_size", flex.IntValue(share.SnapshotSize)); err != nil { + err = fmt.Errorf("Error setting snapshot_size: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share", "read", "set-snapshot_size").GetDiag() + } + if !core.IsNil(share.SourceSnapshot) { + sourceSnapshotMap, err := ResourceIBMIsShareShareSourceSnapshotToMap(share.SourceSnapshot) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share", "read", "source_snapshot-to-map").GetDiag() + } + if err = d.Set("source_snapshot", []map[string]interface{}{sourceSnapshotMap}); err != nil { + err = fmt.Errorf("Error setting source_snapshot: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share", "read", "set-source_snapshot").GetDiag() + } + } latest_syncs := []map[string]interface{}{} if share.LatestSync != nil { latest_sync := make(map[string]interface{}) @@ -1854,6 +1945,7 @@ func shareUpdate(vpcClient *vpcv1.VpcV1, context context.Context, d *schema.Reso shareCRN = "replica_share.0.crn" replicationCronSpec = "replica_share.0.replication_cron_spec" } + if d.HasChange(shareNameSchema) { name := d.Get(shareNameSchema).(string) sharePatchModel.Name = &name @@ -2160,6 +2252,16 @@ func ResourceIBMIsShareMapToShareIdentity(modelMap map[string]interface{}) vpcv1 } return model } +func ResourceIBMIsShareMapToShareSourceSnapshotPrototype(modelMap map[string]interface{}) vpcv1.ShareSourceSnapshotPrototypeIntf { + model := &vpcv1.ShareSourceSnapshotPrototype{} + if modelMap["id"] != nil && modelMap["id"].(string) != "" { + model.ID = core.StringPtr(modelMap["id"].(string)) + } + if modelMap["crn"] != nil && modelMap["crn"].(string) != "" { + model.CRN = core.StringPtr(modelMap["crn"].(string)) + } + return model +} func ResourceIBMIsShareShareReferenceToMap(model *vpcv1.ShareReference) map[string]interface{} { modelMap := make(map[string]interface{}) modelMap["crn"] = *model.CRN @@ -2225,3 +2327,58 @@ func resourceShareLifecycleReasons(lifecycleReasons []vpcv1.ShareLifecycleReason } return lifecycleReasonsList } + +func ResourceIBMIsShareShareSourceSnapshotToMap(model vpcv1.ShareSourceSnapshotIntf) (map[string]interface{}, error) { + if _, ok := model.(*vpcv1.ShareSourceSnapshotShareSnapshotReference); ok { + return ResourceIBMIsShareShareSourceSnapshotShareSnapshotReferenceToMap(model.(*vpcv1.ShareSourceSnapshotShareSnapshotReference)) + } else if _, ok := model.(*vpcv1.ShareSourceSnapshot); ok { + modelMap := make(map[string]interface{}) + model := model.(*vpcv1.ShareSourceSnapshot) + if model.CRN != nil { + modelMap["crn"] = *model.CRN + } + if model.Deleted != nil { + deletedMap, err := ResourceIBMIsShareDeletedToMap(model.Deleted) + if err != nil { + return modelMap, err + } + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + if model.Href != nil { + modelMap["href"] = *model.Href + } + if model.ID != nil { + modelMap["id"] = *model.ID + } + if model.Name != nil { + modelMap["name"] = *model.Name + } + if model.ResourceType != nil { + modelMap["resource_type"] = *model.ResourceType + } + return modelMap, nil + } else { + return nil, fmt.Errorf("Unrecognized vpcv1.ShareSourceSnapshotIntf subtype encountered") + } +} +func ResourceIBMIsShareShareSourceSnapshotShareSnapshotReferenceToMap(model *vpcv1.ShareSourceSnapshotShareSnapshotReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["crn"] = *model.CRN + if model.Deleted != nil { + deletedMap, err := ResourceIBMIsShareDeletedToMap(model.Deleted) + if err != nil { + return modelMap, err + } + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + modelMap["resource_type"] = *model.ResourceType + return modelMap, nil +} +func ResourceIBMIsShareDeletedToMap(model *vpcv1.Deleted) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["more_info"] = *model.MoreInfo + return modelMap, nil +} diff --git a/ibm/service/vpc/resource_ibm_is_share_snapshot.go b/ibm/service/vpc/resource_ibm_is_share_snapshot.go new file mode 100644 index 0000000000..13dcc0b4f5 --- /dev/null +++ b/ibm/service/vpc/resource_ibm_is_share_snapshot.go @@ -0,0 +1,738 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.91.0-d9755c53-20240605-153412 + */ + +package vpc + +import ( + "context" + "fmt" + "log" + "os" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/vpc-go-sdk/vpcv1" +) + +func ResourceIBMIsShareSnapshot() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceIBMIsShareSnapshotCreate, + ReadContext: resourceIBMIsShareSnapshotRead, + UpdateContext: resourceIBMIsShareSnapshotUpdate, + DeleteContext: resourceIBMIsShareSnapshotDelete, + Importer: &schema.ResourceImporter{}, + + CustomizeDiff: customdiff.All( + customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourceTagsCustomizeDiff(diff) + }, + ), + customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourceValidateAccessTags(diff, v) + }), + ), + + Schema: map[string]*schema.Schema{ + "share": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.InvokeValidator("ibm_is_share_snapshot", "share"), + Description: "The file share identifier.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.InvokeValidator("ibm_is_share_snapshot", "name"), + Description: "The name for this share snapshot. The name is unique across all snapshots for the file share.", + }, + "tags": &schema.Schema{ + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString, ValidateFunc: validate.InvokeValidator("ibm_is_share_snapshot", "tags")}, + Set: flex.ResourceIBMVPCHash, + Description: "The [user tags](https://cloud.ibm.com/apidocs/tagging#types-of-tags) associated with this share snapshot.", + }, + "access_tags": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString, ValidateFunc: validate.InvokeValidator("ibm_is_share_snapshot", "access_tags")}, + Set: flex.ResourceIBMVPCHash, + Description: "List of access management tags", + }, + "backup_policy_plan": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, the backup policy plan which created this share snapshot.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "deleted": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about deleted resources.", + }, + }, + }, + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this backup policy plan.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this backup policy plan.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this backup policy plan. The name is unique across all plans in the backup policy.", + }, + "remote": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this region.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The globally unique name for this region.", + }, + }, + }, + }, + }, + }, + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + }, + }, + }, + "captured_at": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The date and time the data capture for this share snapshot was completed.If absent, this snapshot's data has not yet been captured.", + }, + "created_at": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The date and time that the share snapshot was created.", + }, + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The CRN for this share snapshot.", + }, + "fingerprint": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The fingerprint for this snapshot.", + }, + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this share snapshot.", + }, + "lifecycle_state": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The lifecycle state of this share snapshot.", + }, + "minimum_size": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "The minimum size of a share created from this snapshot. When a snapshot is created, this will be set to the size of the `source_share`.", + }, + "resource_group": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The resource group for this file share.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this resource group.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this resource group.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The name for this resource group.", + }, + }, + }, + }, + "resource_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The resource type.", + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The status of the share snapshot:- `available`: The share snapshot is available for use.- `failed`: The share snapshot is irrecoverably unusable.- `pending`: The share snapshot is being provisioned and is not yet usable.- `unusable`: The share snapshot is not currently usable (see `status_reasons`)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future.", + }, + "status_reasons": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The reasons for the current status (if any).", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "code": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "A reason code for the status:- `encryption_key_deleted`: File share snapshot is unusable because its `encryption_key` was deleted- `internal_error`: Internal error (contact IBM support)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future.", + }, + "message": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "An explanation of the status reason.", + }, + "more_info": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Link to documentation about this status reason.", + }, + }, + }, + }, + "zone": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The zone this share snapshot resides in.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "href": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL for this zone.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The globally unique name for this zone.", + }, + }, + }, + }, + "share_snapshot": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The unique identifier for this share snapshot.", + }, + }, + } +} + +func ResourceIBMIsShareSnapshotValidator() *validate.ResourceValidator { + validateSchema := make([]validate.ValidateSchema, 0) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "share", + ValidateFunctionIdentifier: validate.ValidateRegexpLen, + Type: validate.TypeString, + Required: true, + Regexp: `^[-0-9a-z_]+$`, + MinValueLength: 1, + MaxValueLength: 64, + }, + validate.ValidateSchema{ + Identifier: "tags", + ValidateFunctionIdentifier: validate.ValidateRegexpLen, + Type: validate.TypeString, + Optional: true, + Regexp: `^[A-Za-z0-9:_ .-]+$`, + MinValueLength: 1, + MaxValueLength: 128}, + validate.ValidateSchema{ + Identifier: "name", + ValidateFunctionIdentifier: validate.ValidateRegexpLen, + Type: validate.TypeString, + Optional: true, + Regexp: `^([a-z]|[a-z][-a-z0-9]*[a-z0-9]|[0-9][-a-z0-9]*([a-z]|[-a-z][-a-z0-9]*[a-z0-9]))$`, + MinValueLength: 1, + MaxValueLength: 63, + }, + validate.ValidateSchema{ + Identifier: "access_tags", + ValidateFunctionIdentifier: validate.ValidateRegexpLen, + Type: validate.TypeString, + Optional: true, + Regexp: `^([A-Za-z0-9_.-]|[A-Za-z0-9_.-][A-Za-z0-9_ .-]*[A-Za-z0-9_.-]):([A-Za-z0-9_.-]|[A-Za-z0-9_.-][A-Za-z0-9_ .-]*[A-Za-z0-9_.-])$`, + MinValueLength: 1, + MaxValueLength: 128, + }, + ) + + resourceValidator := validate.ResourceValidator{ResourceName: "ibm_is_share_snapshot", Schema: validateSchema} + return &resourceValidator +} + +func resourceIBMIsShareSnapshotCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + vpcClient, err := meta.(conns.ClientSession).VpcV1API() + if err != nil { + // Error is coming from SDK client, so it doesn't need to be discriminated. + tfErr := flex.TerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + createShareSnapshotOptions := &vpcv1.CreateShareSnapshotOptions{} + + createShareSnapshotOptions.SetShareID(d.Get("share").(string)) + if _, ok := d.GetOk("name"); ok { + createShareSnapshotOptions.SetName(d.Get("name").(string)) + } + var userTags *schema.Set + if v, ok := d.GetOk("tags"); ok { + userTags = v.(*schema.Set) + if userTags != nil && userTags.Len() != 0 { + userTagsArray := make([]string, userTags.Len()) + for i, userTag := range userTags.List() { + userTagStr := userTag.(string) + userTagsArray[i] = userTagStr + } + schematicTags := os.Getenv("IC_ENV_TAGS") + var envTags []string + if schematicTags != "" { + envTags = strings.Split(schematicTags, ",") + userTagsArray = append(userTagsArray, envTags...) + } + createShareSnapshotOptions.SetUserTags(userTagsArray) + } + } + shareSnapshot, _, err := vpcClient.CreateShareSnapshotWithContext(context, createShareSnapshotOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("CreateShareSnapshotWithContext failed: %s", err.Error()), "ibm_is_share_snapshot", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + d.SetId(fmt.Sprintf("%s/%s", *createShareSnapshotOptions.ShareID, *shareSnapshot.ID)) + _, err = isWaitForShareSnapshotAvailable(context, vpcClient, *createShareSnapshotOptions.ShareID, *shareSnapshot.ID, d, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return diag.FromErr(err) + } + if _, ok := d.GetOk("access_tags"); ok { + oldList, newList := d.GetChange(isSubnetAccessTags) + err = flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, *shareSnapshot.CRN, "", isAccessTagType) + if err != nil { + log.Printf( + "[ERROR] Error on create of resource share snapshot (%s) access tags: %s", d.Id(), err) + } + } + return resourceIBMIsShareSnapshotRead(context, d, meta) +} + +func resourceIBMIsShareSnapshotRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + vpcClient, err := meta.(conns.ClientSession).VpcV1API() + if err != nil { + tfErr := flex.TerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getShareSnapshotOptions := &vpcv1.GetShareSnapshotOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "sep-id-parts").GetDiag() + } + + getShareSnapshotOptions.SetShareID(parts[0]) + getShareSnapshotOptions.SetID(parts[1]) + + shareSnapshot, response, err := vpcClient.GetShareSnapshotWithContext(context, getShareSnapshotOptions) + if err != nil { + if response != nil && response.StatusCode == 404 { + d.SetId("") + return nil + } + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetShareSnapshotWithContext failed: %s", err.Error()), "ibm_is_share_snapshot", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + if !core.IsNil(shareSnapshot.Name) { + if err = d.Set("name", shareSnapshot.Name); err != nil { + err = fmt.Errorf("Error setting name: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-name").GetDiag() + } + } + if !core.IsNil(shareSnapshot.UserTags) { + if err = d.Set("tags", shareSnapshot.UserTags); err != nil { + err = fmt.Errorf("Error setting tags: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-tags").GetDiag() + } + } + backupPolicyPlanMap := make(map[string]interface{}, 1) + if !core.IsNil(shareSnapshot.BackupPolicyPlan) { + backupPolicyPlanMap, err = ResourceIBMIsShareSnapshotBackupPolicyPlanReferenceToMap(shareSnapshot.BackupPolicyPlan) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "backup_policy_plan-to-map").GetDiag() + } + } + if err = d.Set("backup_policy_plan", []map[string]interface{}{backupPolicyPlanMap}); err != nil { + err = fmt.Errorf("Error setting backup_policy_plan: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-backup_policy_plan").GetDiag() + } + + if !core.IsNil(shareSnapshot.CapturedAt) { + if err = d.Set("captured_at", flex.DateTimeToString(shareSnapshot.CapturedAt)); err != nil { + err = fmt.Errorf("Error setting captured_at: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-captured_at").GetDiag() + } + } + if err = d.Set("created_at", flex.DateTimeToString(shareSnapshot.CreatedAt)); err != nil { + err = fmt.Errorf("Error setting created_at: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-created_at").GetDiag() + } + if err = d.Set("crn", shareSnapshot.CRN); err != nil { + err = fmt.Errorf("Error setting crn: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-crn").GetDiag() + } + if err = d.Set("fingerprint", shareSnapshot.Fingerprint); err != nil { + err = fmt.Errorf("Error setting fingerprint: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-fingerprint").GetDiag() + } + if err = d.Set("href", shareSnapshot.Href); err != nil { + err = fmt.Errorf("Error setting href: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-href").GetDiag() + } + if err = d.Set("lifecycle_state", shareSnapshot.LifecycleState); err != nil { + err = fmt.Errorf("Error setting lifecycle_state: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-lifecycle_state").GetDiag() + } + if err = d.Set("minimum_size", flex.IntValue(shareSnapshot.MinimumSize)); err != nil { + err = fmt.Errorf("Error setting minimum_size: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-minimum_size").GetDiag() + } + if !core.IsNil(shareSnapshot.ResourceGroup) { + resourceGroupMap, err := ResourceIBMIsShareSnapshotResourceGroupReferenceToMap(shareSnapshot.ResourceGroup) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "resource_group-to-map").GetDiag() + } + if err = d.Set("resource_group", []map[string]interface{}{resourceGroupMap}); err != nil { + err = fmt.Errorf("Error setting resource_group: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-resource_group").GetDiag() + } + } + if err = d.Set("resource_type", shareSnapshot.ResourceType); err != nil { + err = fmt.Errorf("Error setting resource_type: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-resource_type").GetDiag() + } + if err = d.Set("status", shareSnapshot.Status); err != nil { + err = fmt.Errorf("Error setting status: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-status").GetDiag() + } + statusReasons := []map[string]interface{}{} + for _, statusReasonsItem := range shareSnapshot.StatusReasons { + statusReasonsItemMap, err := ResourceIBMIsShareSnapshotShareSnapshotStatusReasonToMap(&statusReasonsItem) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "status_reasons-to-map").GetDiag() + } + statusReasons = append(statusReasons, statusReasonsItemMap) + } + if err = d.Set("status_reasons", statusReasons); err != nil { + err = fmt.Errorf("Error setting status_reasons: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-status_reasons").GetDiag() + } + zoneMap, err := ResourceIBMIsShareSnapshotZoneReferenceToMap(shareSnapshot.Zone) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "zone-to-map").GetDiag() + } + if err = d.Set("zone", []map[string]interface{}{zoneMap}); err != nil { + err = fmt.Errorf("Error setting zone: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-zone").GetDiag() + } + if err = d.Set("share_snapshot", shareSnapshot.ID); err != nil { + err = fmt.Errorf("Error setting share_snapshot: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "read", "set-is_share_snapshot_id").GetDiag() + } + accesstags, err := flex.GetGlobalTagsUsingCRN(meta, *shareSnapshot.CRN, "", isAccessTagType) + if err != nil { + log.Printf( + "[ERROR] Error on get of resource share snapshot (%s) access tags: %s", d.Id(), err) + } + d.Set("access_tags", accesstags) + return nil +} + +func resourceIBMIsShareSnapshotUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + vpcClient, err := meta.(conns.ClientSession).VpcV1API() + if err != nil { + tfErr := flex.TerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + updateShareSnapshotOptions := &vpcv1.UpdateShareSnapshotOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "update", "sep-id-parts").GetDiag() + } + + updateShareSnapshotOptions.SetShareID(parts[0]) + updateShareSnapshotOptions.SetID(parts[1]) + + hasChange := false + + getShareSnapshotOptions := &vpcv1.GetShareSnapshotOptions{} + + getShareSnapshotOptions.SetShareID(parts[0]) + getShareSnapshotOptions.SetID(parts[1]) + + _, response, err := vpcClient.GetShareSnapshotWithContext(context, getShareSnapshotOptions) + if err != nil { + if response != nil && response.StatusCode == 404 { + d.SetId("") + return nil + } + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetShareSnapshotWithContext failed: %s", err.Error()), "ibm_is_share_snapshot", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + patchVals := &vpcv1.ShareSnapshotPatch{} + + if d.HasChange("tags") { + var userTags *schema.Set + if v, ok := d.GetOk("tags"); ok { + + userTags = v.(*schema.Set) + if userTags != nil && userTags.Len() != 0 { + userTagsArray := make([]string, userTags.Len()) + for i, userTag := range userTags.List() { + userTagStr := userTag.(string) + userTagsArray[i] = userTagStr + } + schematicTags := os.Getenv("IC_ENV_TAGS") + var envTags []string + if schematicTags != "" { + envTags = strings.Split(schematicTags, ",") + userTagsArray = append(userTagsArray, envTags...) + } + patchVals.UserTags = userTagsArray + hasChange = true + } + } + } + updateShareSnapshotOptions.SetIfMatch(response.Headers.Get("Etag")) + + if hasChange { + updateShareSnapshotOptions.ShareSnapshotPatch, _ = patchVals.AsPatch() + if _, exists := d.GetOk("tags"); d.HasChange("tags") && !exists { + updateShareSnapshotOptions.ShareSnapshotPatch["tags"] = nil + } + + _, _, err = vpcClient.UpdateShareSnapshotWithContext(context, updateShareSnapshotOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("UpdateShareSnapshotWithContext failed: %s", err.Error()), "ibm_is_share_snapshot", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + _, err = isWaitForShareSnapshotAvailable(context, vpcClient, parts[0], parts[1], d, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return diag.FromErr(err) + } + } + if d.HasChange("access_tags") { + oldList, newList := d.GetChange("access_tags") + err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, d.Get(isSnapshotCRN).(string), "", isAccessTagType) + if err != nil { + log.Printf( + "[ERROR] Error on update of resource share snapshot (%s) access tags: %s", d.Id(), err) + } + } + return resourceIBMIsShareSnapshotRead(context, d, meta) +} + +func resourceIBMIsShareSnapshotDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + vpcClient, err := meta.(conns.ClientSession).VpcV1API() + if err != nil { + tfErr := flex.TerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + deleteShareSnapshotOptions := &vpcv1.DeleteShareSnapshotOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_share_snapshot", "delete", "sep-id-parts").GetDiag() + } + + deleteShareSnapshotOptions.SetShareID(parts[0]) + deleteShareSnapshotOptions.SetID(parts[1]) + + _, _, err = vpcClient.DeleteShareSnapshotWithContext(context, deleteShareSnapshotOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeleteShareSnapshotWithContext failed: %s", err.Error()), "ibm_is_share_snapshot", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + d.SetId("") + + return nil +} + +func ResourceIBMIsShareSnapshotBackupPolicyPlanReferenceToMap(model *vpcv1.BackupPolicyPlanReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Deleted != nil { + deletedMap, err := ResourceIBMIsShareSnapshotDeletedToMap(model.Deleted) + if err != nil { + return modelMap, err + } + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + if model.Remote != nil { + remoteMap, err := ResourceIBMIsShareSnapshotBackupPolicyPlanRemoteToMap(model.Remote) + if err != nil { + return modelMap, err + } + modelMap["remote"] = []map[string]interface{}{remoteMap} + } + modelMap["resource_type"] = *model.ResourceType + return modelMap, nil +} + +func ResourceIBMIsShareSnapshotDeletedToMap(model *vpcv1.Deleted) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["more_info"] = *model.MoreInfo + return modelMap, nil +} + +func ResourceIBMIsShareSnapshotBackupPolicyPlanRemoteToMap(model *vpcv1.BackupPolicyPlanRemote) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Region != nil { + regionMap, err := ResourceIBMIsShareSnapshotRegionReferenceToMap(model.Region) + if err != nil { + return modelMap, err + } + modelMap["region"] = []map[string]interface{}{regionMap} + } + return modelMap, nil +} + +func ResourceIBMIsShareSnapshotRegionReferenceToMap(model *vpcv1.RegionReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["name"] = *model.Name + return modelMap, nil +} + +func ResourceIBMIsShareSnapshotResourceGroupReferenceToMap(model *vpcv1.ResourceGroupReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["id"] = *model.ID + modelMap["name"] = *model.Name + return modelMap, nil +} + +func ResourceIBMIsShareSnapshotShareSnapshotStatusReasonToMap(model *vpcv1.ShareSnapshotStatusReason) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["code"] = *model.Code + modelMap["message"] = *model.Message + if model.MoreInfo != nil { + modelMap["more_info"] = *model.MoreInfo + } + return modelMap, nil +} + +func ResourceIBMIsShareSnapshotZoneReferenceToMap(model *vpcv1.ZoneReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = *model.Href + modelMap["name"] = *model.Name + return modelMap, nil +} + +func isWaitForShareSnapshotAvailable(context context.Context, vpcClient *vpcv1.VpcV1, shareid string, shareSnapshotId string, d *schema.ResourceData, timeout time.Duration) (interface{}, error) { + log.Printf("Waiting for share snapshot (%s) to be available.", shareid) + + stateConf := &resource.StateChangeConf{ + Pending: []string{"updating", "pending", "waiting"}, + Target: []string{"available", "failed"}, + Refresh: isShareSnapshotRefreshFunc(context, vpcClient, shareid, shareSnapshotId, d), + Timeout: timeout, + Delay: 10 * time.Second, + MinTimeout: 10 * time.Second, + } + + return stateConf.WaitForState() +} + +func isShareSnapshotRefreshFunc(context context.Context, vpcClient *vpcv1.VpcV1, shareid, shareSnapshotId string, d *schema.ResourceData) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + shareSnapOptions := &vpcv1.GetShareSnapshotOptions{} + + shareSnapOptions.SetShareID(shareid) + shareSnapOptions.SetID(shareSnapshotId) + + shareSnapshot, response, err := vpcClient.GetShareSnapshotWithContext(context, shareSnapOptions) + if err != nil { + return nil, "", fmt.Errorf("Error Getting share snapshot: %s\n%s", err, response) + } + d.Set("status", *shareSnapshot.Status) + if *shareSnapshot.Status == "available" || *shareSnapshot.Status == "failed" { + + if *shareSnapshot.Status == "available" { + if _, ok := d.GetOk("tags"); ok && len(shareSnapshot.UserTags) == 0 { + return shareSnapshot, "pending", nil + } + } + return shareSnapshot, *shareSnapshot.Status, nil + + } + return shareSnapshot, "pending", nil + } +} diff --git a/ibm/service/vpc/resource_ibm_is_share_snapshot_test.go b/ibm/service/vpc/resource_ibm_is_share_snapshot_test.go new file mode 100644 index 0000000000..f297a84024 --- /dev/null +++ b/ibm/service/vpc/resource_ibm_is_share_snapshot_test.go @@ -0,0 +1,323 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package vpc_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/vpc" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/vpc-go-sdk/vpcv1" + "github.com/stretchr/testify/assert" +) + +func TestAccIBMIsShareSnapshotBasic(t *testing.T) { + var conf vpcv1.ShareSnapshot + shareName := fmt.Sprintf("tf-name-share%d", acctest.RandIntRange(10, 100)) + shareSnapshotName := fmt.Sprintf("tf-name-share-snap%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMIsShareSnapshotDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIsShareSnapshotConfigBasic(shareName, shareSnapshotName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMIsShareSnapshotExists("ibm_is_share_snapshot.is_share_snapshot_instance", conf), + resource.TestCheckResourceAttrSet("ibm_is_share_snapshot.is_share_snapshot_instance", "share"), + resource.TestCheckResourceAttrSet("ibm_is_share_snapshot.is_share_snapshot_instance", "tags.#"), + resource.TestCheckResourceAttr("ibm_is_share_snapshot.is_share_snapshot_instance", "name", shareSnapshotName), + ), + }, + }, + }) +} + +func TestAccIBMIsShareSnapshotAllArgs(t *testing.T) { + var conf vpcv1.ShareSnapshot + name := fmt.Sprintf("tf-name-share-snapshot%d", acctest.RandIntRange(10, 100)) + shareName := fmt.Sprintf("tf-name-share%d", acctest.RandIntRange(10, 100)) + // nameUpdate := fmt.Sprintf("tf-name-share-snapshot%d", acctest.RandIntRange(10, 100)) + userTag1 := fmt.Sprintf("tfp-share-tag-%d", acctest.RandIntRange(10, 100)) + userTag2 := fmt.Sprintf("tfp-share-tag-%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMIsShareSnapshotDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIsShareSnapshotConfig(shareName, name, userTag1), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMIsShareSnapshotExists("ibm_is_share_snapshot.is_share_snapshot_instance", conf), + resource.TestCheckResourceAttr("ibm_is_share_snapshot.is_share_snapshot_instance", "name", name), + resource.TestCheckResourceAttrSet("ibm_is_share_snapshot.is_share_snapshot_instance", "tags.#"), + ), + }, + resource.TestStep{ + Config: testAccCheckIBMIsShareSnapshotConfig(shareName, name, userTag2), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ibm_is_share_snapshot.is_share_snapshot_instance", "name", name), + resource.TestCheckResourceAttrSet("ibm_is_share_snapshot.is_share_snapshot_instance", "tags.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMIsShareSnapshotConfigBasic(shareName, shareSnapshotName string) string { + return testAccCheckIbmIsShareConfigBasic(shareName) + fmt.Sprintf(` + resource "ibm_is_share_snapshot" "is_share_snapshot_instance" { + share = ibm_is_share.is_share.id + name = "%s" + } + `, shareSnapshotName) +} + +func testAccCheckIBMIsShareSnapshotConfig(shareName string, name, tags string) string { + return testAccCheckIbmIsShareConfigBasic(shareName) + fmt.Sprintf(` + resource "ibm_is_share_snapshot" "is_share_snapshot_instance" { + share = ibm_is_share.is_share.id + name = "%s" + tags = ["%s"] + } + `, name, tags) +} + +func testAccCheckIBMIsShareSnapshotExists(n string, obj vpcv1.ShareSnapshot) resource.TestCheckFunc { + + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + vpcClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).VpcV1API() + if err != nil { + return err + } + + getShareSnapshotOptions := &vpcv1.GetShareSnapshotOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + getShareSnapshotOptions.SetShareID(parts[0]) + getShareSnapshotOptions.SetID(parts[1]) + + shareSnapshot, _, err := vpcClient.GetShareSnapshot(getShareSnapshotOptions) + if err != nil { + return err + } + + obj = *shareSnapshot + return nil + } +} + +func testAccCheckIBMIsShareSnapshotDestroy(s *terraform.State) error { + vpcClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).VpcV1API() + if err != nil { + return err + } + for _, rs := range s.RootModule().Resources { + if rs.Type != "ibm_is_share_snapshot" { + continue + } + + getShareSnapshotOptions := &vpcv1.GetShareSnapshotOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + getShareSnapshotOptions.SetShareID(parts[0]) + getShareSnapshotOptions.SetID(parts[1]) + + // Try to find the key + _, response, err := vpcClient.GetShareSnapshot(getShareSnapshotOptions) + + if err == nil { + return fmt.Errorf("ShareSnapshot still exists: %s", rs.Primary.ID) + } else if response.StatusCode != 404 { + return fmt.Errorf("Error checking for ShareSnapshot (%s) has been destroyed: %s", rs.Primary.ID, err) + } + } + + return nil +} + +func TestResourceIBMIsShareSnapshotBackupPolicyPlanReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + deletedModel := make(map[string]interface{}) + deletedModel["more_info"] = "https://cloud.ibm.com/apidocs/vpc#deleted-resources" + + regionReferenceModel := make(map[string]interface{}) + regionReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + regionReferenceModel["name"] = "us-south" + + backupPolicyPlanRemoteModel := make(map[string]interface{}) + backupPolicyPlanRemoteModel["region"] = []map[string]interface{}{regionReferenceModel} + + model := make(map[string]interface{}) + model["deleted"] = []map[string]interface{}{deletedModel} + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178" + model["id"] = "r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178" + model["name"] = "my-policy-plan" + model["remote"] = []map[string]interface{}{backupPolicyPlanRemoteModel} + model["resource_type"] = "backup_policy_plan" + + assert.Equal(t, result, model) + } + + deletedModel := new(vpcv1.Deleted) + deletedModel.MoreInfo = core.StringPtr("https://cloud.ibm.com/apidocs/vpc#deleted-resources") + + regionReferenceModel := new(vpcv1.RegionReference) + regionReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + regionReferenceModel.Name = core.StringPtr("us-south") + + backupPolicyPlanRemoteModel := new(vpcv1.BackupPolicyPlanRemote) + backupPolicyPlanRemoteModel.Region = regionReferenceModel + + model := new(vpcv1.BackupPolicyPlanReference) + model.Deleted = deletedModel + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/backup_policies/r134-076191ba-49c2-4763-94fd-c70de73ee2e6/plans/r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178") + model.ID = core.StringPtr("r134-6da51cfe-6f7b-4638-a6ba-00e9c327b178") + model.Name = core.StringPtr("my-policy-plan") + model.Remote = backupPolicyPlanRemoteModel + model.ResourceType = core.StringPtr("backup_policy_plan") + + result, err := vpc.ResourceIBMIsShareSnapshotBackupPolicyPlanReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMIsShareSnapshotDeletedToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["more_info"] = "https://cloud.ibm.com/apidocs/vpc#deleted-resources" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.Deleted) + model.MoreInfo = core.StringPtr("https://cloud.ibm.com/apidocs/vpc#deleted-resources") + + result, err := vpc.ResourceIBMIsShareSnapshotDeletedToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMIsShareSnapshotBackupPolicyPlanRemoteToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + regionReferenceModel := make(map[string]interface{}) + regionReferenceModel["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + regionReferenceModel["name"] = "us-south" + + model := make(map[string]interface{}) + model["region"] = []map[string]interface{}{regionReferenceModel} + + assert.Equal(t, result, model) + } + + regionReferenceModel := new(vpcv1.RegionReference) + regionReferenceModel.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + regionReferenceModel.Name = core.StringPtr("us-south") + + model := new(vpcv1.BackupPolicyPlanRemote) + model.Region = regionReferenceModel + + result, err := vpc.ResourceIBMIsShareSnapshotBackupPolicyPlanRemoteToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMIsShareSnapshotRegionReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south" + model["name"] = "us-south" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.RegionReference) + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south") + model.Name = core.StringPtr("us-south") + + result, err := vpc.ResourceIBMIsShareSnapshotRegionReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMIsShareSnapshotResourceGroupReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://resource-controller.cloud.ibm.com/v2/resource_groups/fee82deba12e4c0fb69c3b09d1f12345" + model["id"] = "fee82deba12e4c0fb69c3b09d1f12345" + model["name"] = "my-resource-group" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ResourceGroupReference) + model.Href = core.StringPtr("https://resource-controller.cloud.ibm.com/v2/resource_groups/fee82deba12e4c0fb69c3b09d1f12345") + model.ID = core.StringPtr("fee82deba12e4c0fb69c3b09d1f12345") + model.Name = core.StringPtr("my-resource-group") + + result, err := vpc.ResourceIBMIsShareSnapshotResourceGroupReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMIsShareSnapshotShareSnapshotStatusReasonToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["code"] = "encryption_key_deleted" + model["message"] = "testString" + model["more_info"] = "https://cloud.ibm.com/docs/key-protect?topic=key-protect-restore-keys" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ShareSnapshotStatusReason) + model.Code = core.StringPtr("encryption_key_deleted") + model.Message = core.StringPtr("testString") + model.MoreInfo = core.StringPtr("https://cloud.ibm.com/docs/key-protect?topic=key-protect-restore-keys") + + result, err := vpc.ResourceIBMIsShareSnapshotShareSnapshotStatusReasonToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestResourceIBMIsShareSnapshotZoneReferenceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["href"] = "https://us-south.iaas.cloud.ibm.com/v1/regions/us-south/zones/us-south-1" + model["name"] = "us-south-1" + + assert.Equal(t, result, model) + } + + model := new(vpcv1.ZoneReference) + model.Href = core.StringPtr("https://us-south.iaas.cloud.ibm.com/v1/regions/us-south/zones/us-south-1") + model.Name = core.StringPtr("us-south-1") + + result, err := vpc.ResourceIBMIsShareSnapshotZoneReferenceToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/vpc/resource_ibm_is_share_test.go b/ibm/service/vpc/resource_ibm_is_share_test.go index e3f0b678cf..c4ee7f2d14 100644 --- a/ibm/service/vpc/resource_ibm_is_share_test.go +++ b/ibm/service/vpc/resource_ibm_is_share_test.go @@ -316,6 +316,53 @@ func TestAccIbmIsShareOriginShare(t *testing.T) { }) } +func TestAccIbmIsShareFromShareSnapshot(t *testing.T) { + var conf vpcv1.Share + + // name := fmt.Sprintf("tf-fs-name-%d", acctest.RandIntRange(10, 100)) + subnetName := fmt.Sprintf("tf-subnet-%d", acctest.RandIntRange(10, 100)) + vpcname := fmt.Sprintf("tf-vpc-name-%d", acctest.RandIntRange(10, 100)) + shareName := fmt.Sprintf("tf-share-%d", acctest.RandIntRange(10, 100)) + shareName1 := fmt.Sprintf("tf-share1-%d", acctest.RandIntRange(10, 100)) + shareSnapName := fmt.Sprintf("tf-share-snap-%d", acctest.RandIntRange(10, 100)) + tEMode1 := "user_managed" + // tEMode2 := "none" + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIbmIsShareDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIbmIsShareConfigShareSnapshotConfig(vpcname, subnetName, tEMode1, shareName, shareSnapName, shareName1), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIbmIsShareExists("ibm_is_share.is_share", conf), + resource.TestCheckResourceAttr("ibm_is_share.is_share", "name", shareName), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share", "id"), + resource.TestCheckResourceAttr("ibm_is_share.is_share", "allowed_transit_encryption_modes.0", tEMode1), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share", "accessor_binding_role"), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share_from_snapshot", "source_snapshot.0.crn"), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share_from_snapshot", "source_snapshot.0.name"), + ), + }, + { + Config: testAccCheckIbmIsShareConfigShareSnapshotConfig(vpcname, subnetName, tEMode1, shareName, shareSnapName, shareName1), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIbmIsShareExists("ibm_is_share.is_share", conf), + resource.TestCheckResourceAttr("ibm_is_share.is_share", "name", shareName), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share", "id"), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share", "allowed_transit_encryption_modes.#"), + resource.TestCheckResourceAttr("ibm_is_share.is_share", "allowed_transit_encryption_modes.0", tEMode1), + resource.TestCheckResourceAttr("ibm_is_share.is_share_from_snapshot", "name", shareName1), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share", "accessor_binding_role"), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share", "accessor_bindings.#"), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share_from_snapshot", "source_snapshot.0.crn"), + resource.TestCheckResourceAttrSet("ibm_is_share.is_share_from_snapshot", "source_snapshot.0.name"), + ), + }, + }, + }) +} + func testAccCheckIbmIsShareConfigVNIID(vpcName, sname, targetName, vniName, shareName string) string { return fmt.Sprintf(` data "ibm_resource_group" "group" { @@ -379,6 +426,43 @@ func testAccCheckIbmIsShareConfigOriginShareConfig(vpcName, sname, tEMode, share `, vpcName, sname, acc.ISCIDR, tEMode, shareName, shareName1) } +func testAccCheckIbmIsShareConfigShareSnapshotConfig(vpcName, sname, tEMode, shareName, shareSnapName, shareName1 string) string { + return fmt.Sprintf(` + + resource "ibm_is_vpc" "testacc_vpc" { + name = "%s" + } + resource "ibm_is_subnet" "testacc_subnet" { + name = "%s" + vpc = ibm_is_vpc.testacc_vpc.id + zone = "us-south-1" + ipv4_cidr_block = "%s" + } + resource "ibm_is_share" "is_share" { + allowed_transit_encryption_modes = ["%s"] + zone = "us-south-1" + size = 220 + name = "%s" + profile = "dp2" + tags = ["tfp-acc-test-share-tag-1"] + } + + resource "ibm_is_share_snapshot" "is_share_snapshot" { + share = ibm_is_share.is_share.id + name = "%s" + tags = ["tfp-acc-test-share-tag-1"] + } + resource "ibm_is_share" "is_share_from_snapshot" { + source_snapshot{ + id = ibm_is_share_snapshot.is_share_snapshot.share_snapshot + } + size = 220 + name = "%s" + profile = "dp2" + } + `, vpcName, sname, acc.ISCIDR, tEMode, shareName, shareSnapName, shareName1) +} + func testAccCheckIbmIsShareConfigBasic(name string) string { return fmt.Sprintf(` resource "ibm_is_share" "is_share" { diff --git a/website/docs/d/is_backup_policy_job.html.markdown b/website/docs/d/is_backup_policy_job.html.markdown index 3f817ab700..7aa2031459 100644 --- a/website/docs/d/is_backup_policy_job.html.markdown +++ b/website/docs/d/is_backup_policy_job.html.markdown @@ -90,6 +90,28 @@ In addition to all argument references listed, you can access the following attr - `id` - (String) The unique identifier for this virtual server instance. - `name` - (String) The unique user-defined name for this virtual server instance. - `resource_type` - (String) The resource type. +- `source_share` - (List) The source share this backup was created from (may be [deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)) + + Nested scheme for `source_volume`: + - `crn` - (String) The CRN for this share. + - `deleted` - (List) If present, this property indicates the referenced resource has been deleted and provides some supplementary information. + + Nested scheme for `deleted`: + - `more_info` - (String) Link to documentation about deleted resources. + - `href` - (String) The URL for this share. + - `id` - (String) The unique identifier for this share. + - `remote` - (Optional, List) If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable. + Nested schema for **remote**: + - `account` - (Optional, List) If present, this property indicates that the referenced resource is remote to thisaccount, and identifies the owning account. + Nested schema for **account**: + - `id` - (Computed, String) The unique identifier for this account. + - `resource_type` - (Computed, String) The resource type. + - `region` - (Optional, List) If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region. + Nested schema for **region**: + - `href` - (Computed, String) The URL for this region. + - `name` - (Computed, String) The globally unique name for this region. + - `name` - (String) The unique user-defined name for this share. + - `resource_type` - (String) The resource type. - `status` - (String) The status of the backup policy job.The enumerated values for this property will expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the backup policy job on which the unexpected property value was encountered. - `status_reasons` - (List) The reasons for the current status (if any).The enumerated reason code values for this property will expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected reason code was encountered. @@ -112,6 +134,16 @@ In addition to all argument references listed, you can access the following attr - `more_info` - (String) Link to documentation about deleted resources. - `href` - (String) The URL for this snapshot. - `id` - (String) The unique identifier for this snapshot. + - `remote` - (Optional, List) If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable. + Nested schema for **remote**: + - `account` - (Optional, List) If present, this property indicates that the referenced resource is remote to thisaccount, and identifies the owning account. + Nested schema for **account**: + - `id` - (Computed, String) The unique identifier for this account. + - `resource_type` - (Computed, String) The resource type. + - `region` - (Optional, List) If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region. + Nested schema for **region**: + - `href` - (Computed, String) The URL for this region. + - `name` - (Computed, String) The globally unique name for this region. - `name` - (String) The user-defined name for this snapshot. - `resource_type` - (String) The resource type. diff --git a/website/docs/d/is_backup_policy_jobs.html.markdown b/website/docs/d/is_backup_policy_jobs.html.markdown index b686469335..c027d32a70 100644 --- a/website/docs/d/is_backup_policy_jobs.html.markdown +++ b/website/docs/d/is_backup_policy_jobs.html.markdown @@ -95,6 +95,28 @@ In addition to all argument references listed, you can access the following attr - `name` - (String) The globally unique name for this region. - `name` - (String) The unique user-defined name for this volume. - `resource_type` - (String) The resource type. + - `source_share` - (List) The source share this backup was created from (may be [deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)) + + Nested scheme for `source_volume`: + - `crn` - (String) The CRN for this share. + - `deleted` - (List) If present, this property indicates the referenced resource has been deleted and provides some supplementary information. + + Nested scheme for `deleted`: + - `more_info` - (String) Link to documentation about deleted resources. + - `href` - (String) The URL for this share. + - `id` - (String) The unique identifier for this share. + - `remote` - (Optional, List) If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable. + Nested schema for **remote**: + - `account` - (Optional, List) If present, this property indicates that the referenced resource is remote to thisaccount, and identifies the owning account. + Nested schema for **account**: + - `id` - (Computed, String) The unique identifier for this account. + - `resource_type` - (Computed, String) The resource type. + - `region` - (Optional, List) If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region. + Nested schema for **region**: + - `href` - (Computed, String) The URL for this region. + - `name` - (Computed, String) The globally unique name for this region. + - `name` - (String) The unique user-defined name for this share. + - `resource_type` - (String) The resource type. - `status` - (String) The status of the backup policy job.The enumerated values for this property will expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the backup policy job on which the unexpected property value was encountered. - `status_reasons` - (List) The reasons for the current status (if any).The enumerated reason code values for this property will expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected reason code was encountered. @@ -117,5 +139,15 @@ In addition to all argument references listed, you can access the following attr - `href` - (String) The URL for this snapshot. - `id` - (String) The unique identifier for this snapshot. - `name` - (String) The user-defined name for this snapshot. + - `remote` - (Optional, List) If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable. + Nested schema for **remote**: + - `account` - (Optional, List) If present, this property indicates that the referenced resource is remote to thisaccount, and identifies the owning account. + Nested schema for **account**: + - `id` - (Computed, String) The unique identifier for this account. + - `resource_type` - (Computed, String) The resource type. + - `region` - (Optional, List) If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region. + Nested schema for **region**: + - `href` - (Computed, String) The URL for this region. + - `name` - (Computed, String) The globally unique name for this region. - `resource_type` - (String) The resource type. diff --git a/website/docs/d/is_share.html.markdown b/website/docs/d/is_share.html.markdown index 4f24e0c1aa..00aba29562 100644 --- a/website/docs/d/is_share.html.markdown +++ b/website/docs/d/is_share.html.markdown @@ -126,6 +126,18 @@ Nested `latest_sync` blocks have the following structure: - `id` - The unique identifier for this file share. - `name` - The unique user-defined name for this file share. - `resource_type` - The resource type. +- `snapshot_count` - (Integer) The total number of snapshots for this share. +- `snapshot_size` - (Integer) The total size (in gigabytes) of snapshots used for this file share. +- `source_snapshot` - (List) The snapshot from which this share was cloned.This property will be present when the share was created from a snapshot.The resources supported by this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in thefuture. + Nested schema for **source_snapshot**: + - `crn` - (String) The CRN for this share snapshot. + - `deleted` - (List) If present, this property indicates the referenced resource has been deleted, and providessome supplementary information. + Nested schema for **deleted**: + - `more_info` - (String) Link to documentation about deleted resources. + - `href` - (String) The URL for this share snapshot. + - `id` - (String) The unique identifier for this share snapshot. + - `name` - (String) The name for this share snapshot. The name is unique across all snapshots for the file share. + - `resource_type` - (String) The resource type. - `tags` - (String) User tags associated for to the share. - `zone` - The name of the zone this file share will reside in. diff --git a/website/docs/d/is_share_snapshot.html.markdown b/website/docs/d/is_share_snapshot.html.markdown new file mode 100644 index 0000000000..483cca0256 --- /dev/null +++ b/website/docs/d/is_share_snapshot.html.markdown @@ -0,0 +1,87 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_is_share_snapshot" +description: |- + Get information about ShareSnapshot +subcategory: "VPC infrastructure" +--- + +# ibm_is_share_snapshot + +Provides a read-only data source to retrieve information about a ShareSnapshot. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +resource "ibm_is_share" "example" { + zone = "us-south-1" + size = 220 + name = "%s" + profile = "dp2" +} + +resource "ibm_is_share_snapshot" "example" { + name = "my-example-share-snapshot" + share = ibm_is_share.example.id + tags = ["my-example-share-snapshot-tag"] +} +data "ibm_is_share_snapshot" "example" { + share_snapshot = ibm_is_share_snapshot.is_share_snapshot_instance.is_share_snapshot_id + share = ibm_is_share.example.id +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +- `share_snapshot` - (Required, Forces new resource, String) The share snapshot identifier. +- `share` - (Required, Forces new resource, String) The file share identifier. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +- `access_tags` - (Array of Strings) Access management tags associated with the snapshot. +- `id` - The unique identifier of the ShareSnapshot. +- `backup_policy_plan` - (List) If present, the backup policy plan which created this share snapshot. + Nested schema for **backup_policy_plan**: + - `deleted` - (List) If present, this property indicates the referenced resource has been deleted, and providessome supplementary information. + Nested schema for **deleted**: + - `more_info` - (String) Link to documentation about deleted resources. + - `href` - (String) The URL for this backup policy plan. + - `id` - (String) The unique identifier for this backup policy plan. + - `name` - (String) The name for this backup policy plan. The name is unique across all plans in the backup policy. + - `remote` - (List) If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable. + Nested schema for **remote**: + - `region` - (List) If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region. + Nested schema for **region**: + - `href` - (String) The URL for this region. + - `name` - (String) The globally unique name for this region. + - `resource_type` - (String) The resource type. +- `captured_at` - (String) The date and time the data capture for this share snapshot was completed.If absent, this snapshot's data has not yet been captured. +- `created_at` - (String) The date and time that the share snapshot was created. +- `crn` - (String) The CRN for this share snapshot. +- `fingerprint` - (String) The fingerprint for this snapshot. +- `href` - (String) The URL for this share snapshot. +- `lifecycle_state` - (String) The lifecycle state of this share snapshot. +- `minimum_size` - (Integer) The minimum size of a share created from this snapshot. When a snapshot is created, this will be set to the size of the `source_share`. +- `name` - (String) The name for this share snapshot. The name is unique across all snapshots for the file share. +- `resource_group` - (List) The resource group for this file share. + Nested schema for **resource_group**: + - `href` - (String) The URL for this resource group. + - `id` - (String) The unique identifier for this resource group. + - `name` - (String) The name for this resource group. +- `resource_type` - (String) The resource type. +- `status` - (String) The status of the share snapshot:- `available`: The share snapshot is available for use.- `failed`: The share snapshot is irrecoverably unusable.- `pending`: The share snapshot is being provisioned and is not yet usable.- `unusable`: The share snapshot is not currently usable (see `status_reasons`)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future. +- `status_reasons` - (List) The reasons for the current status (if any). + Nested schema for **status_reasons**: + - `code` - (String) A reason code for the status:- `encryption_key_deleted`: File share snapshot is unusable because its `encryption_key` was deleted- `internal_error`: Internal error (contact IBM support)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future. + - `message` - (String) An explanation of the status reason. + - `more_info` - (String) Link to documentation about this status reason. +- `tags` - (List) The [user tags](https://cloud.ibm.com/apidocs/tagging#types-of-tags) associated with this share snapshot. +- `zone` - (List) The zone this share snapshot resides in. + Nested schema for **zone**: + - `href` - (String) The URL for this zone. + - `name` - (String) The globally unique name for this zone. + diff --git a/website/docs/d/is_share_snapshots.html.markdown b/website/docs/d/is_share_snapshots.html.markdown new file mode 100644 index 0000000000..89adbca854 --- /dev/null +++ b/website/docs/d/is_share_snapshots.html.markdown @@ -0,0 +1,93 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_is_share_snapshots" +description: |- + Get information about ShareSnapshotCollection +subcategory: "VPC infrastructure" +--- + +# ibm_is_share_snapshots + +Provides a read-only data source to retrieve information about a ShareSnapshotCollection. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +resource "ibm_is_share" "example" { + zone = "us-south-1" + size = 220 + name = "%s" + profile = "dp2" +} + +resource "ibm_is_share_snapshot" "example" { + name = "my-example-share-snapshot" + share = ibm_is_share.example.id + tags = ["my-example-share-snapshot-tag"] +} +data "ibm_is_share_snapshots" "example" { + share = ibm_is_share.example.id +} + +// Retrieve all the snapshots from all the shares +data "ibm_is_share_snapshots" "example1" { +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +- `backup_policy_plan` - (Optional, String) Filters the collection to backup policy jobs with a `backup_policy_plan.id` property matching the specified identifier. +- `name` - (Optional, String) Filters the collection to resources with a `name` property matching the exact specified name. +- `share` - (Optional, String) The file share identifier. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +- `snapshots` - (List) A page of share snapshots. + Nested schema for **snapshots**: + - `access_tags` - (Array of Strings) Access management tags associated with the snapshot. + - `backup_policy_plan` - (List) If present, the backup policy plan which created this share snapshot. + Nested schema for **backup_policy_plan**: + - `deleted` - (List) If present, this property indicates the referenced resource has been deleted, and providessome supplementary information. + Nested schema for **deleted**: + - `more_info` - (String) Link to documentation about deleted resources. + - `href` - (String) The URL for this backup policy plan. + - `id` - (String) The unique identifier for this backup policy plan. + - `name` - (String) The name for this backup policy plan. The name is unique across all plans in the backup policy. + - `remote` - (List) If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable. + Nested schema for **remote**: + - `region` - (List) If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region. + Nested schema for **region**: + - `href` - (String) The URL for this region. + - `name` - (String) The globally unique name for this region. + - `resource_type` - (String) The resource type. + - `captured_at` - (String) The date and time the data capture for this share snapshot was completed.If absent, this snapshot's data has not yet been captured. + - `created_at` - (String) The date and time that the share snapshot was created. + - `crn` - (String) The CRN for this share snapshot. + - `fingerprint` - (String) The fingerprint for this snapshot. + - `href` - (String) The URL for this share snapshot. + - `id` - (String) The unique identifier for this share snapshot. + - `lifecycle_state` - (String) The lifecycle state of this share snapshot. + - `minimum_size` - (Integer) The minimum size of a share created from this snapshot. When a snapshot is created, this will be set to the size of the `source_share`. + - `name` - (String) The name for this share snapshot. The name is unique across all snapshots for the file share. + - `resource_group` - (List) The resource group for this file share. + Nested schema for **resource_group**: + - `href` - (String) The URL for this resource group. + - `id` - (String) The unique identifier for this resource group. + - `name` - (String) The name for this resource group. + - `resource_type` - (String) The resource type. + - `status` - (String) The status of the share snapshot:- `available`: The share snapshot is available for use.- `failed`: The share snapshot is irrecoverably unusable.- `pending`: The share snapshot is being provisioned and is not yet usable.- `unusable`: The share snapshot is not currently usable (see `status_reasons`)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future. + - `status_reasons` - (List) The reasons for the current status (if any). + Nested schema for **status_reasons**: + - `code` - (String) A reason code for the status:- `encryption_key_deleted`: File share snapshot is unusable because its `encryption_key` was deleted- `internal_error`: Internal error (contact IBM support)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future. + - `message` - (String) An explanation of the status reason. + - `more_info` - (String) Link to documentation about this status reason. + - `tags` - (List) The [user tags](https://cloud.ibm.com/apidocs/tagging#types-of-tags) associated with this share snapshot. + - `zone` - (List) The zone this share snapshot resides in. + Nested schema for **zone**: + - `href` - (String) The URL for this zone. + - `name` - (String) The globally unique name for this zone. + diff --git a/website/docs/d/is_shares.html.markdown b/website/docs/d/is_shares.html.markdown index 32e70b92f2..a3ea8acfab 100644 --- a/website/docs/d/is_shares.html.markdown +++ b/website/docs/d/is_shares.html.markdown @@ -114,5 +114,17 @@ The following attributes are exported: - `id` - (String) The unique identifier for this file share. - `name` - (String) The unique user-defined name for this file share. - `resource_type` - (String) The resource type. + - `snapshot_count` - (Integer) The total number of snapshots for this share. + - `snapshot_size` - (Integer) The total size (in gigabytes) of snapshots used for this file share. + - `source_snapshot` - (List) The snapshot from which this share was cloned.This property will be present when the share was created from a snapshot.The resources supported by this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in thefuture. + Nested schema for **source_snapshot**: + - `crn` - (String) The CRN for this share snapshot. + - `deleted` - (List) If present, this property indicates the referenced resource has been deleted, and providessome supplementary information. + Nested schema for **deleted**: + - `more_info` - (String) Link to documentation about deleted resources. + - `href` - (String) The URL for this share snapshot. + - `id` - (String) The unique identifier for this share snapshot. + - `name` - (String) The name for this share snapshot. The name is unique across all snapshots for the file share. + - `resource_type` - (String) The resource type. - `total_count` - The total number of resources across all pages. diff --git a/website/docs/r/is_backup_policy.html.markdown b/website/docs/r/is_backup_policy.html.markdown index aa0a61b83d..01c72caf01 100644 --- a/website/docs/r/is_backup_policy.html.markdown +++ b/website/docs/r/is_backup_policy.html.markdown @@ -55,7 +55,7 @@ Review the argument reference that you can specify for your resource. ~> **Note** `match_resource_types` is deprecated. Please use `match_resource_type` instead. -- `match_resource_type` - (Optional, String) The resource type this backup policy will apply to. Resources that have both a matching type and a matching user tag will be subject to the backup policy. The default value is `["volume"]`. Allowed values are `volume`,`instance`. +- `match_resource_type` - (Optional, String) The resource type this backup policy will apply to. Resources that have both a matching type and a matching user tag will be subject to the backup policy. The default value is `["volume"]`. Allowed values are `volume`,`instance`,`share`. - `match_user_tags` - (Required, List) The user tags this backup policy applies to. Resources that have both a matching user tag and a matching type will be subject to the backup policy. - `name` - (Required, String) The user-defined name for this backup policy. Names must be unique within the region this backup policy resides in. - `resource_group` - (Optional, List) The resource group id, to use. If unspecified, the account's [default resource group](https://cloud.ibm.com/apidocs/resource-manager#introduction) is used. diff --git a/website/docs/r/is_share.html.markdown b/website/docs/r/is_share.html.markdown index 2092145308..8e8a5dab34 100644 --- a/website/docs/r/is_share.html.markdown +++ b/website/docs/r/is_share.html.markdown @@ -233,6 +233,13 @@ The following arguments are supported: - `size` - (Required, Integer) The size of the file share rounded up to the next gigabyte. - `source_share` - (Optional, String) The ID of the source file share for this replica file share. The specified file share must not already have a replica, and must not be a replica. - `source_share_crn` - (Optional, String) The CRN of the source file share. +- `source_snapshot` - (List) The snapshot from which this share was cloned.This property will be present when the share was created from a snapshot.The resources supported by this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in thefuture. + Nested schema for **source_snapshot**: + - `crn` - (Optional, String) The CRN for this share snapshot. + - `id` - (Optional, String) The unique identifier for this share snapshot. + + ~> **NOTE** + `crn` and `id` are mutually exclusive for source_snapshot - `tags` - (Optional, List of Strings) The list of user tags to attach to the share. - `zone` - (Required, string) The globally unique name for this zone. @@ -351,6 +358,18 @@ Nested `latest_sync` blocks have the following structure: - `code` - A snake case string succinctly identifying the status reason. - `message` - An explanation of the status reason. - `more_info` - Link to documentation about this status reason. +- `source_snapshot` - (List) The snapshot from which this share was cloned.This property will be present when the share was created from a snapshot.The resources supported by this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in thefuture. + Nested schema for **source_snapshot**: + - `crn` - (String) The CRN for this share snapshot. + - `deleted` - ( List) If present, this property indicates the referenced resource has been deleted, and providessome supplementary information. + Nested schema for **deleted**: + - `more_info` - (Computed, String) Link to documentation about deleted resources. + - `href` - (String) The URL for this share snapshot. + - `id` - (String) The unique identifier for this share snapshot. + - `name` - (String) The name for this share snapshot. The name is unique across all snapshots for the file share. + - `resource_type` - (String) The resource type. +- `snapshot_count` - (Integer) The total number of snapshots for this share. +- `snapshot_size` - (Integer) The total size (in gigabytes) of snapshots used for this file share. - `tags` - (String) User tags associated for to the share. diff --git a/website/docs/r/is_share_snapshot.html.markdown b/website/docs/r/is_share_snapshot.html.markdown new file mode 100644 index 0000000000..1ab26daf15 --- /dev/null +++ b/website/docs/r/is_share_snapshot.html.markdown @@ -0,0 +1,98 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_is_share_snapshot" +description: |- + Manages ShareSnapshot. +subcategory: "VPC infrastructure" +--- + +# ibm_is_share_snapshot + +Create, update, and delete ShareSnapshots with this resource. + +## Example Usage + +```hcl +resource "ibm_is_share" "example" { + zone = "us-south-1" + size = 220 + name = "%s" + profile = "dp2" +} + +resource "ibm_is_share_snapshot" "example" { + name = "my-example-share-snapshot" + share = ibm_is_share.example.id + tags = ["my-example-share-snapshot-tag"] +} +``` + +## Argument Reference + +You can specify the following arguments for this resource. + +- `name` - (Optional, String) The name for this share snapshot. The name is unique across all snapshots for the file share. +- `share` - (Required, Forces new resource, String) The file share identifier. +- `tags` - (Optional, List) The [user tags](https://cloud.ibm.com/apidocs/tagging#types-of-tags) associated with this share snapshot. + +## Attribute Reference + +After your resource is created, you can read values from the listed arguments and the following attributes. + +- `id` - The unique identifier of the ShareSnapshot. +- `backup_policy_plan` - (List) If present, the backup policy plan which created this share snapshot. + Nested schema for **backup_policy_plan**: + _ `deleted` - (List) If present, this property indicates the referenced resource has been deleted, and providessome supplementary information. + Nested schema for **deleted**: + - `more_info` - (String) Link to documentation about deleted resources. + - `href` - (String) The URL for this backup policy plan. + - `id` - (String) The unique identifier for this backup policy plan. + - `name` - (String) The name for this backup policy plan. The name is unique across all plans in the backup policy. + - `remote` - (List) If present, this property indicates that the resource associated with this referenceis remote and therefore may not be directly retrievable. + Nested schema for **remote**: + - `region` - (List) If present, this property indicates that the referenced resource is remote to thisregion, and identifies the native region. + Nested schema for **region**: + - `href` - (String) The URL for this region. + - `name` - (String) The globally unique name for this region. + - `resource_type` - (String) The resource type. +- `captured_at` - (String) The date and time the data capture for this share snapshot was completed.If absent, this snapshot's data has not yet been captured. +- `created_at` - (String) The date and time that the share snapshot was created. +- `crn` - (String) The CRN for this share snapshot. +- `fingerprint` - (String) The fingerprint for this snapshot. +- `href` - (String) The URL for this share snapshot. +- `is_share_snapshot_id` - (String) The unique identifier for this share snapshot. +- `lifecycle_state` - (String) The lifecycle state of this share snapshot. +- `minimum_size` - (Integer) The minimum size of a share created from this snapshot. When a snapshot is created, this will be set to the size of the `source_share`. +- `resource_group` - (List) The resource group for this file share. + Nested schema for **resource_group**: + - `href` - (String) The URL for this resource group. + - `id` - (String) The unique identifier for this resource group. + - `name` - (String) The name for this resource group. +- `resource_type` - (String) The resource type. +- `status` - (String) The status of the share snapshot:- `available`: The share snapshot is available for use.- `failed`: The share snapshot is irrecoverably unusable.- `pending`: The share snapshot is being provisioned and is not yet usable.- `unusable`: The share snapshot is not currently usable (see `status_reasons`)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future. +- `status_reasons` - (List) The reasons for the current status (if any). + Nested schema for **status_reasons**: + - `code` - (String) A reason code for the status:- `encryption_key_deleted`: File share snapshot is unusable because its `encryption_key` was deleted- `internal_error`: Internal error (contact IBM support)The enumerated values for this property may[expand](https://cloud.ibm.com/apidocs/vpc#property-value-expansion) in the future. + - `message` - (String) An explanation of the status reason. + - `more_info` - (String) Link to documentation about this status reason. +- `zone` - (List) The zone this share snapshot resides in. + Nested schema for **zone**: + - `href` - (String) The URL for this zone. + - `name` - (String) The globally unique name for this zone. + + +## Import + +You can import the `ibm_is_share_snapshot` resource by using `id`. +The `id` property can be formed from `share_id`, and `is_share_snapshot_id` in the following format: + +
+<share_id>/<is_share_snapshot_id> ++- `share_id`: A string. The file share identifier. +- `is_share_snapshot_id`: A string in the format `r006-e13ee54f-baa4-40d3-b35c-b9ec163972b4`. The unique identifier for this share snapshot. + +# Syntax +
+$ terraform import ibm_is_share_snapshot.is_share_snapshot <share_id>/<is_share_snapshot_id> +