From fb4fba7aba737eb00f691bea19df531ec03d8c7f Mon Sep 17 00:00:00 2001 From: Daniel Byrne Date: Wed, 5 Jun 2024 17:03:04 +0100 Subject: [PATCH 1/2] Respect store_value argument when creating apikey for ServiceId #4615 --- .../resource_ibm_iam_service_api_key.go | 5 +- .../resource_ibm_iam_service_api_key_test.go | 55 ++++++++++++++++--- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/ibm/service/iamidentity/resource_ibm_iam_service_api_key.go b/ibm/service/iamidentity/resource_ibm_iam_service_api_key.go index 2f547a637e..637d2dc72d 100644 --- a/ibm/service/iamidentity/resource_ibm_iam_service_api_key.go +++ b/ibm/service/iamidentity/resource_ibm_iam_service_api_key.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2017, 2021 All Rights Reserved. +// Copyright IBM Corp. 2017, 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package iamidentity @@ -75,6 +75,7 @@ func ResourceIBMIAMServiceAPIKey() *schema.Resource { "store_value": { Type: schema.TypeBool, Optional: true, + Default: true, DiffSuppressFunc: flex.ApplyOnce, Description: "Boolean value deciding whether API key value is retrievable in the future", }, @@ -171,7 +172,7 @@ func resourceIBMIAMServiceAPIkeyCreate(d *schema.ResourceData, meta interface{}) createAPIKeyOptions.Apikey = &apikeyString } - if strvalue, ok := d.GetOk("store_value"); ok { + if strvalue := d.Get("store_value"); strvalue != nil { value := strvalue.(bool) createAPIKeyOptions.StoreValue = &value } diff --git a/ibm/service/iamidentity/resource_ibm_iam_service_api_key_test.go b/ibm/service/iamidentity/resource_ibm_iam_service_api_key_test.go index 3da10c5daa..b59e9a9835 100644 --- a/ibm/service/iamidentity/resource_ibm_iam_service_api_key_test.go +++ b/ibm/service/iamidentity/resource_ibm_iam_service_api_key_test.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2017, 2021 All Rights Reserved. +// Copyright IBM Corp. 2017, 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package iamidentity_test @@ -22,6 +22,7 @@ func TestAccIBMIAMServiceAPIKey_Basic(t *testing.T) { serviceName := fmt.Sprintf("terraform_iam_ser_%d", acctest.RandIntRange(10, 100)) name := fmt.Sprintf("terraform_iam_%d", acctest.RandIntRange(10, 100)) updateName := fmt.Sprintf("terraform_iam_%d", acctest.RandIntRange(10, 100)) + storeValue := true resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -29,16 +30,17 @@ func TestAccIBMIAMServiceAPIKey_Basic(t *testing.T) { CheckDestroy: testAccCheckIBMIAMServiceAPIKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMIAMServiceAPIKeyBasic(serviceName, name), + Config: testAccCheckIBMIAMServiceAPIKeyBasic(serviceName, name, storeValue), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMIAMServiceAPIKeyExists("ibm_iam_service_api_key.testacc_apiKey", apiKey), + testAccCheckIBMIAMServiceAPIKeyExistsWithValidation("ibm_iam_service_api_key.testacc_apiKey", apiKey, storeValue), resource.TestCheckResourceAttr("ibm_iam_service_api_key.testacc_apiKey", "name", name), + resource.TestCheckResourceAttrSet("ibm_iam_service_api_key.testacc_apiKey", "apikey"), ), }, { Config: testAccCheckIBMIAMServiceAPIKeyUpdateWithSameName(serviceName, name), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMIAMServiceAPIKeyExists("ibm_iam_service_api_key.testacc_apiKey", apiKey), + testAccCheckIBMIAMServiceAPIKeyExistsWithValidation("ibm_iam_service_api_key.testacc_apiKey", apiKey, storeValue), resource.TestCheckResourceAttr("ibm_iam_service_api_key.testacc_apiKey", "name", name), resource.TestCheckResourceAttr("ibm_iam_service_api_key.testacc_apiKey", "description", "Service API Key for test scenario1"), ), @@ -54,11 +56,34 @@ func TestAccIBMIAMServiceAPIKey_Basic(t *testing.T) { }) } +func TestAccIBMIAMServiceAPIKey_doNotStoreApikeyValue(t *testing.T) { + var apiKey string + serviceName := fmt.Sprintf("terraform_iam_ser_%d", acctest.RandIntRange(10, 100)) + name := fmt.Sprintf("terraform_iam_%d", acctest.RandIntRange(10, 100)) + storeValue := false + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMIAMServiceAPIKeyDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMIAMServiceAPIKeyBasic(serviceName, name, storeValue), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMIAMServiceAPIKeyExistsWithValidation("ibm_iam_service_api_key.testacc_apiKey", apiKey, storeValue), + resource.TestCheckResourceAttr("ibm_iam_service_api_key.testacc_apiKey", "name", name), + ), + }, + }, + }) +} + func TestAccIBMIAMServiceAPIKey_import(t *testing.T) { var apiKey string serviceName := fmt.Sprintf("terraform_iam_ser_%d", acctest.RandIntRange(10, 100)) name := fmt.Sprintf("terraform_iam_%d", acctest.RandIntRange(10, 100)) resourceName := "ibm_iam_service_api_key.testacc_apiKey" + storeValue := true resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -68,7 +93,7 @@ func TestAccIBMIAMServiceAPIKey_import(t *testing.T) { { Config: testAccCheckIBMIAMServiceAPIKeyImport(serviceName, name), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckIBMIAMServiceAPIKeyExists(resourceName, apiKey), + testAccCheckIBMIAMServiceAPIKeyExistsWithValidation(resourceName, apiKey, storeValue), resource.TestCheckResourceAttr(resourceName, "name", name), resource.TestCheckResourceAttr(resourceName, "description", "Service API Key for test scenario2"), ), @@ -77,6 +102,9 @@ func TestAccIBMIAMServiceAPIKey_import(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "store_value", + }, }, }, }) @@ -105,7 +133,7 @@ func testAccCheckIBMIAMServiceAPIKeyDestroy(s *terraform.State) error { return nil } -func testAccCheckIBMIAMServiceAPIKeyExists(n string, apiKey string) resource.TestCheckFunc { +func testAccCheckIBMIAMServiceAPIKeyExistsWithValidation(n string, apiKey string, apikeyValueExpected bool) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -127,12 +155,22 @@ func testAccCheckIBMIAMServiceAPIKeyExists(n string, apiKey string) resource.Tes return err } + if apikeyValueExpected { + if foundAPIKey.Apikey == nil { + return fmt.Errorf("apikey value should be present") + } + } else { + if foundAPIKey.Apikey != nil { + return fmt.Errorf("apikey value should not be present") + } + } + apiKey = *foundAPIKey.ID return nil } } -func testAccCheckIBMIAMServiceAPIKeyBasic(serviceName, name string) string { +func testAccCheckIBMIAMServiceAPIKeyBasic(serviceName, name string, storeValue bool) string { return fmt.Sprintf(` resource "ibm_iam_service_id" "serviceID" { @@ -142,8 +180,9 @@ func testAccCheckIBMIAMServiceAPIKeyBasic(serviceName, name string) string { resource "ibm_iam_service_api_key" "testacc_apiKey" { name = "%s" iam_service_id = ibm_iam_service_id.serviceID.iam_id + store_value = "%t" } - `, serviceName, name) + `, serviceName, name, storeValue) } func testAccCheckIBMIAMServiceAPIKeyUpdateWithSameName(serviceName, name string) string { From 9359e9e10c2db55189c1c26f71824baeaa9fa20c Mon Sep 17 00:00:00 2001 From: Sushmitha M <86282159+sushmitha1506@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:15:56 +0530 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20Adding=20=20default=20prefixfiletr?= =?UTF-8?q?=20for=20TGW=20connection=20resource=20=20depe=E2=80=A6=20(#540?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Adding default prefixfiletr for TGW connection resource dependency:none * chore: Adding default prefixfiletr for TGW connection resource dependency:none --------- Co-authored-by: sushmitha M --- .../data_source_ibm_tg_gateway.go | 10 +++++++++ .../resource_ibm_tg_gateway_connection.go | 21 +++++++++++++++++++ website/docs/d/tg_gateway.html.markdown | 6 +++--- website/docs/r/tg_connection.html.markdown | 7 ++++++- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ibm/service/transitgateway/data_source_ibm_tg_gateway.go b/ibm/service/transitgateway/data_source_ibm_tg_gateway.go index acedf31ef5..cef140d1d1 100644 --- a/ibm/service/transitgateway/data_source_ibm_tg_gateway.go +++ b/ibm/service/transitgateway/data_source_ibm_tg_gateway.go @@ -139,6 +139,13 @@ func DataSourceIBMTransitGateway() *schema.Resource { Type: schema.TypeString, Computed: true, }, + tgDefaultPrefixFilter: { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.InvokeValidator("ibm_tg_connection_prefix_filter", tgAction), + Description: "Whether to permit or deny the prefix filter", + }, }, }, }, @@ -284,6 +291,9 @@ func dataSourceIBMTransitGatewayConnectionsRead(d *schema.ResourceData, meta int if instance.Status != nil { tgConn[tgConnectionStatus] = *instance.Status } + if instance.PrefixFiltersDefault != nil { + tgConn[tgDefaultPrefixFilter] = *instance.PrefixFiltersDefault + } connections = append(connections, tgConn) diff --git a/ibm/service/transitgateway/resource_ibm_tg_gateway_connection.go b/ibm/service/transitgateway/resource_ibm_tg_gateway_connection.go index 077f40151c..f352294675 100644 --- a/ibm/service/transitgateway/resource_ibm_tg_gateway_connection.go +++ b/ibm/service/transitgateway/resource_ibm_tg_gateway_connection.go @@ -40,6 +40,7 @@ const ( tgRemoteTunnelIp = "remote_tunnel_ip" tgZone = "zone" tgMtu = "mtu" + tgDefaultPrefixFilter = "default_prefix_filter" ) func ResourceIBMTransitGatewayConnection() *schema.Resource { @@ -177,6 +178,13 @@ func ResourceIBMTransitGatewayConnection() *schema.Resource { Computed: true, Description: "The crn of the transit gateway", }, + tgDefaultPrefixFilter: { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.InvokeValidator("ibm_tg_connection_prefix_filter", tgAction), + Description: "Whether to permit or deny the prefix filter", + }, }, } } @@ -265,6 +273,10 @@ func resourceIBMTransitGatewayConnectionCreate(d *schema.ResourceData, meta inte zoneIdentity.Name = &zoneName createTransitGatewayConnectionOptions.SetZone(zoneIdentity) } + if _, ok := d.GetOk(tgDefaultPrefixFilter); ok { + default_prefix_filter := d.Get(tgDefaultPrefixFilter).(string) + createTransitGatewayConnectionOptions.SetPrefixFiltersDefault(default_prefix_filter) + } tgConnections, response, err := client.CreateTransitGatewayConnection(createTransitGatewayConnectionOptions) if err != nil { @@ -374,6 +386,9 @@ func resourceIBMTransitGatewayConnectionRead(d *schema.ResourceData, meta interf if instance.RequestStatus != nil { d.Set(tgRequestStatus, *instance.RequestStatus) } + if instance.PrefixFiltersDefault != nil { + d.Set(tgDefaultPrefixFilter, *instance.PrefixFiltersDefault) + } d.Set(tgConnectionId, *instance.ID) d.Set(tgGatewayId, gatewayId) getTransitGatewayOptions := &transitgatewayapisv1.GetTransitGatewayOptions{ @@ -421,6 +436,12 @@ func resourceIBMTransitGatewayConnectionUpdate(d *schema.ResourceData, meta inte updateTransitGatewayConnectionOptions.Name = &name } } + if d.HasChange(tgDefaultPrefixFilter) { + if d.Get(tgDefaultPrefixFilter) != nil { + prefixFilter := d.Get(tgDefaultPrefixFilter).(string) + updateTransitGatewayConnectionOptions.PrefixFiltersDefault = &prefixFilter + } + } _, response, err = client.UpdateTransitGatewayConnection(updateTransitGatewayConnectionOptions) if err != nil { diff --git a/website/docs/d/tg_gateway.html.markdown b/website/docs/d/tg_gateway.html.markdown index 5e05d418d2..ac0694dcce 100644 --- a/website/docs/d/tg_gateway.html.markdown +++ b/website/docs/d/tg_gateway.html.markdown @@ -1,4 +1,3 @@ ---- subcategory: "Transit Gateway" layout: "ibm" @@ -13,6 +12,7 @@ Retrieve information of an existing IBM Cloud infrastructure transit gateway as ## Example usage +--- ```terraform resource "ibm_tg_gateway" "new_tg_gw" { name = "transit-gateway-1" @@ -20,12 +20,11 @@ resource "ibm_tg_gateway" "new_tg_gw" { global = true resource_group = "30951d2dff914dafb26455a88c0c0092" } - data "ibm_tg_gateway" "ds_tggateway" { name = ibm_tg_gateway.new_tg_gw.name } ``` - +--- ## Argument reference Review the argument references that you can specify for your data source. @@ -63,3 +62,4 @@ In addition to the argument reference list, you can access the following attribu - `zone` - (String) The location of the GRE tunnel. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections. - `status` - (String) The gateway status. - `updated_at` - (Timestamp) The date and time resource is last updated. +- `default_prefix_filter` - (String) Whether to permit or deny the prefix filter, Default value for action for prefix filters diff --git a/website/docs/r/tg_connection.html.markdown b/website/docs/r/tg_connection.html.markdown index 62e7648ac6..e32e9c3da6 100644 --- a/website/docs/r/tg_connection.html.markdown +++ b/website/docs/r/tg_connection.html.markdown @@ -1,4 +1,4 @@ ---- + subcategory: "Transit Gateway" layout: "ibm" page_title: "IBM : tg_connection" @@ -11,6 +11,7 @@ Create, update and delete for the transit gateway's connection resource. For mor ## Example usage +--- ```terraform resource "ibm_tg_connection" "test_ibm_tg_connection" { gateway = ibm_tg_gateway.test_tg_gateway.id @@ -20,6 +21,7 @@ resource "ibm_tg_connection" "test_ibm_tg_connection" { } ``` +--- ## Argument reference Review the argument references that you can specify for your resource. @@ -37,6 +39,7 @@ Review the argument references that you can specify for your resource. - `remote_gateway_ip` - (Optional, Forces new resource, String) - The remote gateway IP address. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections. - `remote_tunnel_ip` - (Optional, Forces new resource, String) - The remote tunnel IP address. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections. - `zone` - (Optional, Forces new resource, String) - The location of the GRE tunnel. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections. +- `default_prefix_filter` - (Optinal, String) Whether to permit or deny the prefix filter ## Attribute reference @@ -60,7 +63,9 @@ The `ibm_tg_connection` resource can be imported by using transit gateway ID and **Example** +--- ``` $ terraform import ibm_tg_connection.example 5ffda12064634723b079acdb018ef308/cea6651a-bd0a-4438-9f8a-a0770bbf3ebb ``` +---