-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Data Source: azurerm_container_registry
#1642
Merged
tombuildsstuff
merged 7 commits into
hashicorp:master
from
schoren:feature-datasource-acr
Jul 25, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
512c104
Add 'azurerm_container_image' data source
schoren bb18cba
Add 'azurerm_container_image' documentation
schoren 23346ac
Fix data source implementation and test
schoren 8282048
Fix datasource docs
schoren b233cef
Add link to datasource docs
schoren 17caf45
Fixes in data source
schoren b6e0b31
Ensuring the data source exists, rather than the resource
tombuildsstuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmContainerRegistry() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmContainerRegistryRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validateAzureRMContainerRegistryName, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
"location": locationForDataSourceSchema(), | ||
"admin_enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"admin_password": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"admin_username": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"login_server": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sku": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"storage_account_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmContainerRegistryRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).containerRegistryClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Container Registry %q was not found in Resource Group %q", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on Azure Container Registry %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
d.Set("name", resp.Name) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azureRMNormalizeLocation(*location)) | ||
} | ||
d.Set("admin_enabled", resp.AdminUserEnabled) | ||
d.Set("login_server", resp.LoginServer) | ||
|
||
if sku := resp.Sku; sku != nil { | ||
d.Set("sku", string(sku.Tier)) | ||
} | ||
|
||
if account := resp.StorageAccount; account != nil { | ||
d.Set("storage_account_id", account.ID) | ||
} | ||
|
||
if *resp.AdminUserEnabled { | ||
credsResp, err := client.ListCredentials(ctx, resourceGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("Error making Read request on Azure Container Registry %s for Credentials: %s", name, err) | ||
} | ||
|
||
d.Set("admin_username", credsResp.Username) | ||
for _, v := range *credsResp.Passwords { | ||
d.Set("admin_password", v.Value) | ||
break | ||
} | ||
} else { | ||
d.Set("admin_username", "") | ||
d.Set("admin_password", "") | ||
} | ||
|
||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} |
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,46 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAzureRMContainerRegistry_basic(t *testing.T) { | ||
ri := acctest.RandInt() | ||
config := testAccDataSourceAzureRMContainerRegistry_basic(ri) | ||
|
||
dataSourceName := "data.azurerm_container_registry.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMContainerRegistryDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "location"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "admin_enabled"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "login_server"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMContainerRegistry_basic(rInt int) string { | ||
resource := testAccAzureRMContainerRegistry_basicManaged(rInt, testLocation(), "Basic") | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
data "azurerm_container_registry" "test" { | ||
name = "${azurerm_container_registry.test.name}" | ||
resource_group_name = "${azurerm_container_registry.test.resource_group_name}" | ||
} | ||
`, resource) | ||
} |
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
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
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,52 @@ | ||
--- | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_container_registry" | ||
sidebar_current: "docs-azurerm-datasource-container-registry" | ||
description: |- | ||
Get information about an Container Registry | ||
|
||
--- | ||
|
||
# Data Source: azurerm_container_registry | ||
|
||
Use this data source to access information about a Container Registry | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_container_registry" "test" { | ||
name = "testacr" | ||
resource_group_name = "test" | ||
} | ||
|
||
output "login_server" { | ||
value = "${data.azurerm_container_registry.test.login_server}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) The name of the Container Registry. | ||
* `resource_group_name` - (Required) The Name of the Resource Group where this Container Registry exists. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The Container Registry ID. | ||
|
||
* `login_server` - The URL that can be used to log into the container registry. | ||
|
||
* `admin_username` - The Username associated with the Container Registry Admin account - if the admin account is enabled. | ||
|
||
* `admin_password` - The Password associated with the Container Registry Admin account - if the admin account is enabled. | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
|
||
* `location` - The Azure Region in which this Container Registry exists. | ||
|
||
* `admin_enabled` - Is the Administrator account enabled for this Container Registry. | ||
|
||
* `sku` - The SKU of this Container Registry, such as `Basic`. | ||
|
||
* `storage_account_id` - The ID of the Storage Account used for this Container Registry. This is only returned for `Classic` SKU's. | ||
|
||
* `tags` - A map of tags assigned to the Container Registry. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-reviewing this I noticed this was checking the resource (
azurerm_container_registry.test
) rather than the data source (which has thedata.
prefix) - I've pushed a commit to fix this (I hope you don't mind!)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course not! Thanks for taking the time to review this and making this fix. Sorry for all this little erros
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not at all - apologies I missed it the first time around; thanks for this contribution, this'll go out in v1.12 :)