Skip to content

Commit

Permalink
Merge branch 'master' into vpn-advanceconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm committed Jun 12, 2024
2 parents 7cabc95 + 9359e9e commit 1fb0d4e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 14 deletions.
5 changes: 3 additions & 2 deletions ibm/service/iamidentity/resource_ibm_iam_service_api_key.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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
}
Expand Down
55 changes: 47 additions & 8 deletions ibm/service/iamidentity/resource_ibm_iam_service_api_key_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,23 +22,25 @@ 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) },
Providers: acc.TestAccProviders,
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"),
),
Expand All @@ -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) },
Expand All @@ -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"),
),
Expand All @@ -77,6 +102,9 @@ func TestAccIBMIAMServiceAPIKey_import(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"store_value",
},
},
},
})
Expand Down Expand Up @@ -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]
Expand All @@ -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" {
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions ibm/service/transitgateway/data_source_ibm_tg_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
Expand Down Expand Up @@ -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)

Expand Down
21 changes: 21 additions & 0 deletions ibm/service/transitgateway/resource_ibm_tg_gateway_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
tgRemoteTunnelIp = "remote_tunnel_ip"
tgZone = "zone"
tgMtu = "mtu"
tgDefaultPrefixFilter = "default_prefix_filter"
)

func ResourceIBMTransitGatewayConnection() *schema.Resource {
Expand Down Expand Up @@ -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",
},
},
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions website/docs/d/tg_gateway.html.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---

subcategory: "Transit Gateway"
layout: "ibm"
Expand All @@ -13,19 +12,19 @@ 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"
location = "us-south"
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.

Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion website/docs/r/tg_connection.html.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

subcategory: "Transit Gateway"
layout: "ibm"
page_title: "IBM : tg_connection"
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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

Expand All @@ -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
```
---

0 comments on commit 1fb0d4e

Please sign in to comment.