-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9478 from BedeGaming/azurerm-keyvault
provider/azurerm: key_vault resource and client_config datasource
- Loading branch information
Showing
19 changed files
with
2,126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
builtin/providers/azurerm/data_source_arm_client_config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package azurerm | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceArmClientConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmClientConfigRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"client_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tenant_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"subscription_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient) | ||
|
||
d.SetId(time.Now().UTC().String()) | ||
d.Set("client_id", client.clientId) | ||
d.Set("tenant_id", client.tenantId) | ||
d.Set("subscription_id", client.subscriptionId) | ||
|
||
return nil | ||
} |
48 changes: 48 additions & 0 deletions
48
builtin/providers/azurerm/data_source_arm_client_config_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package azurerm | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAzureRMClientConfig_basic(t *testing.T) { | ||
clientId := os.Getenv("ARM_CLIENT_ID") | ||
tenantId := os.Getenv("ARM_TENANT_ID") | ||
subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckArmClientConfig_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAzureRMClientConfigAttr("data.azurerm_client_config.current", "client_id", clientId), | ||
testAzureRMClientConfigAttr("data.azurerm_client_config.current", "tenant_id", tenantId), | ||
testAzureRMClientConfigAttr("data.azurerm_client_config.current", "subscription_id", subscriptionId), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// Wraps resource.TestCheckResourceAttr to prevent leaking values to console | ||
// in case of mismatch | ||
func testAzureRMClientConfigAttr(name, key, value string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
err := resource.TestCheckResourceAttr(name, key, value)(s) | ||
if err != nil { | ||
// return fmt.Errorf("%s: Attribute '%s', failed check (values hidden)", name, key) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccCheckArmClientConfig_basic = ` | ||
data "azurerm_client_config" "current" { } | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAzureRMKeyVault_importBasic(t *testing.T) { | ||
resourceName := "azurerm_key_vault.test" | ||
|
||
ri := acctest.RandInt() | ||
config := fmt.Sprintf(testAccAzureRMKeyVault_basic, ri, ri) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMKeyVaultDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: config, | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.