Skip to content
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

tests: add tf linting R checks & fix errors #4212

Merged
merged 2 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ matrix:
include:
- name: "make lint"
script: GOGC=20 make lint
- name: "make tflint"
script: make tflint
- name: "make test"
script: make test
- name: "make website-lint"
Expand Down
19 changes: 13 additions & 6 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ default: build
tools:
@echo "==> installing required tooling..."
@sh "$(CURDIR)/scripts/gogetcookie.sh"
GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint
GO111MODULE=on go install github.com/bflad/tfproviderlint/cmd/tfproviderlint

build: fmtcheck
go install
Expand All @@ -39,6 +40,12 @@ lint:
@echo "==> Checking source code against linters..."
golangci-lint run ./...

tflint:
@echo "==> Checking source code against terraform provider linters..."
@tfproviderlint \
-R001 -R002 -R003 -R004\
./$(PKG_NAME)

test-docker:
docker run --rm -v $$(pwd):/go/src/github.com/terraform-providers/terraform-provider-azurerm -w /go/src/github.com/terraform-providers/terraform-provider-azurerm golang:1.12 make test

Expand All @@ -61,17 +68,17 @@ testacc: fmtcheck
debugacc: fmtcheck
TF_ACC=1 dlv test $(TEST) --headless --listen=:2345 --api-version=2 -- -test.v $(TESTARGS)

website-lint:
@echo "==> Checking website against linters..."
@misspell -error -source=text -i hdinsight website/

tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

website-lint:
@echo "==> Checking website against linters..."
@misspell -error -source=text -i hdinsight website/

website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
Expand Down
12 changes: 4 additions & 8 deletions azurerm/data_source_azuread_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,12 @@ func dataSourceArmAzureADApplicationRead(d *schema.ResourceData, meta interface{
d.Set("available_to_other_tenants", application.AvailableToOtherTenants)
d.Set("oauth2_allow_implicit_flow", application.Oauth2AllowImplicitFlow)

if s := application.IdentifierUris; s != nil {
if err := d.Set("identifier_uris", *s); err != nil {
return fmt.Errorf("Error setting `identifier_uris`: %+v", err)
}
if err := d.Set("identifier_uris", application.IdentifierUris); err != nil {
return fmt.Errorf("Error setting `identifier_uris`: %+v", err)
}

if s := application.ReplyUrls; s != nil {
if err := d.Set("reply_urls", *s); err != nil {
return fmt.Errorf("Error setting `reply_urls`: %+v", err)
}
if err := d.Set("reply_urls", application.ReplyUrls); err != nil {
return fmt.Errorf("Error setting `reply_urls`: %+v", err)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions azurerm/data_source_managed_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func dataSourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) erro
}

if props := resp.DiskProperties; props != nil {
if diskSize := props.DiskSizeGB; diskSize != nil {
d.Set("disk_size_gb", *diskSize)
}

d.Set("disk_size_gb", props.DiskSizeGB)

if osType := props.OsType; osType != "" {
d.Set("os_type", string(osType))
}
Expand Down
6 changes: 3 additions & 3 deletions azurerm/data_source_maps_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
)

func TestAccDataSourceAzureRMMapsAccount(t *testing.T) {
func TestAccDataSourceAzureRMMapsAccount_basic(t *testing.T) {
dataSourceName := "data.azurerm_maps_account.test"
rInt := tf.AccRandTimeInt()
location := testLocation()
Expand All @@ -18,7 +18,7 @@ func TestAccDataSourceAzureRMMapsAccount(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMMapsAccount(rInt, location),
Config: testAccDataSourceAzureRMMapsAccount_basic(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
resource.TestCheckResourceAttrSet(dataSourceName, "name"),
Expand All @@ -35,7 +35,7 @@ func TestAccDataSourceAzureRMMapsAccount(t *testing.T) {
})
}

func testAccDataSourceAzureRMMapsAccount(rInt int, location string) string {
func testAccDataSourceAzureRMMapsAccount_basic(rInt int, location string) string {
template := testAccAzureRMMapsAccount_tags(rInt, location)
return fmt.Sprintf(`
%s
Expand Down
9 changes: 3 additions & 6 deletions azurerm/data_source_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,12 @@ func dataSourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{})
if iface.IPConfigurations != nil && len(*iface.IPConfigurations) > 0 {
configs := *iface.IPConfigurations

if configs[0].InterfaceIPConfigurationPropertiesFormat != nil {
privateIPAddress := configs[0].InterfaceIPConfigurationPropertiesFormat.PrivateIPAddress
d.Set("private_ip_address", *privateIPAddress)
}
d.Set("private_ip_address", configs[0].InterfaceIPConfigurationPropertiesFormat.PrivateIPAddress)

addresses := make([]interface{}, 0)
for _, config := range configs {
if config.InterfaceIPConfigurationPropertiesFormat != nil {
addresses = append(addresses, *config.InterfaceIPConfigurationPropertiesFormat.PrivateIPAddress)
addresses = append(addresses, config.InterfaceIPConfigurationPropertiesFormat.PrivateIPAddress)
}
}

Expand All @@ -220,7 +217,7 @@ func dataSourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{})
}

if iface.VirtualMachine != nil {
d.Set("virtual_machine_id", *iface.VirtualMachine.ID)
d.Set("virtual_machine_id", iface.VirtualMachine.ID)
} else {
d.Set("virtual_machine_id", "")
}
Expand Down
12 changes: 3 additions & 9 deletions azurerm/data_source_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,9 @@ func dataSourceArmSnapshotRead(d *schema.ResourceData, meta interface{}) error {

if data := resp.CreationData; data != nil {
d.Set("creation_option", string(data.CreateOption))
if data.SourceURI != nil {
d.Set("source_uri", *data.SourceURI)
}
if data.SourceResourceID != nil {
d.Set("source_resource_id", *data.SourceResourceID)
}
if data.StorageAccountID != nil {
d.Set("storage_account_id", *data.StorageAccountID)
}
d.Set("source_uri", data.SourceURI)
d.Set("source_resource_id", data.SourceResourceID)
d.Set("storage_account_id", data.StorageAccountID)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions azurerm/resource_arm_analysis_services_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ func resourceArmAnalysisServicesServerRead(d *schema.ResourceData, meta interfac
}

if serverProps := server.ServerProperties; serverProps != nil {
if serverProps.AsAdministrators == nil || serverProps.AsAdministrators.Members == nil {
if serverProps.AsAdministrators == nil {
d.Set("admin_users", []string{})
} else {
d.Set("admin_users", *serverProps.AsAdministrators.Members)
d.Set("admin_users", serverProps.AsAdministrators.Members)
}

enablePowerBi, fwRules := flattenAnalysisServicesServerFirewallSettings(serverProps)
Expand Down
5 changes: 1 addition & 4 deletions azurerm/resource_arm_data_factory_linked_service_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ func resourceArmDataFactoryLinkedServiceMySQLRead(d *schema.ResourceData, meta i
}

d.Set("additional_properties", mysql.AdditionalProperties)

if mysql.Description != nil {
d.Set("description", *mysql.Description)
}
d.Set("description", mysql.Description)

annotations := flattenDataFactoryAnnotations(mysql.Annotations)
if err := d.Set("annotations", annotations); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ func resourceArmDataFactoryLinkedServicePostgreSQLRead(d *schema.ResourceData, m
}

d.Set("additional_properties", postgresql.AdditionalProperties)

if postgresql.Description != nil {
d.Set("description", *postgresql.Description)
}
d.Set("description", postgresql.Description)

annotations := flattenDataFactoryAnnotations(postgresql.Annotations)
if err := d.Set("annotations", annotations); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,7 @@ func resourceArmDataFactoryLinkedServiceSQLServerRead(d *schema.ResourceData, me
}

d.Set("additional_properties", sqlServer.AdditionalProperties)

if sqlServer.Description != nil {
d.Set("description", *sqlServer.Description)
}
d.Set("description", sqlServer.Description)

annotations := flattenDataFactoryAnnotations(sqlServer.Annotations)
if err := d.Set("annotations", annotations); err != nil {
Expand Down
8 changes: 3 additions & 5 deletions azurerm/resource_arm_eventgrid_event_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func resourceArmEventGridEventSubscriptionRead(d *schema.ResourceData, meta inte
d.Set("event_delivery_schema", string(props.EventDeliverySchema))

if props.Topic != nil && *props.Topic != "" {
d.Set("topic_name", *props.Topic)
d.Set("topic_name", props.Topic)
}

if storageQueueEndpoint, ok := props.Destination.AsStorageQueueEventSubscriptionDestination(); ok {
Expand Down Expand Up @@ -355,10 +355,8 @@ func resourceArmEventGridEventSubscriptionRead(d *schema.ResourceData, meta inte
}
}

if labels := props.Labels; labels != nil {
if err := d.Set("labels", *labels); err != nil {
return fmt.Errorf("Error setting `labels` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err)
}
if err := d.Set("labels", props.Labels); err != nil {
return fmt.Errorf("Error setting `labels` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err)
}
}

Expand Down
1 change: 0 additions & 1 deletion azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ func resourceArmFunctionApp() *schema.Resource {
"virtual_network_name": {
Type: schema.TypeString,
Optional: true,
Computed: false,
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
},
"cors": azure.SchemaWebCorsSettings(),
},
Expand Down
4 changes: 1 addition & 3 deletions azurerm/resource_arm_local_network_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}
d.Set("gateway_address", props.GatewayIPAddress)

if lnas := props.LocalNetworkAddressSpace; lnas != nil {
if prefixes := lnas.AddressPrefixes; prefixes != nil {
d.Set("address_space", *prefixes)
}
d.Set("address_space", lnas.AddressPrefixes)
}
flattenedSettings := flattenLocalNetworkGatewayBGPSettings(props.BgpSettings)
if err := d.Set("bgp_settings", flattenedSettings); err != nil {
Expand Down
14 changes: 4 additions & 10 deletions azurerm/resource_arm_managed_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ func resourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) error
}

if props := resp.DiskProperties; props != nil {
if diskSize := props.DiskSizeGB; diskSize != nil {
d.Set("disk_size_gb", *diskSize)
}
d.Set("disk_size_gb", props.DiskSizeGB)
if osType := props.OsType; osType != "" {
d.Set("os_type", string(osType))
}
Expand Down Expand Up @@ -314,13 +312,9 @@ func resourceArmManagedDiskDelete(d *schema.ResourceData, meta interface{}) erro

func flattenAzureRmManagedDiskCreationData(d *schema.ResourceData, creationData *compute.CreationData) {
d.Set("create_option", string(creationData.CreateOption))
d.Set("source_resource_id", creationData.SourceResourceID)
d.Set("source_uri", creationData.SourceURI)
if ref := creationData.ImageReference; ref != nil {
d.Set("image_reference_id", *ref.ID)
}
if id := creationData.SourceResourceID; id != nil {
d.Set("source_resource_id", *id)
}
if creationData.SourceURI != nil {
d.Set("source_uri", *creationData.SourceURI)
d.Set("image_reference_id", ref.ID)
}
}
2 changes: 1 addition & 1 deletion azurerm/resource_arm_metric_alertrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func resourceArmMetricAlertRuleRead(d *schema.ResourceData, meta interface{}) er
if ruleCondition != nil {
if thresholdRuleCondition, ok := ruleCondition.AsThresholdRuleCondition(); ok && thresholdRuleCondition != nil {
d.Set("operator", string(thresholdRuleCondition.Operator))
d.Set("threshold", *thresholdRuleCondition.Threshold)
d.Set("threshold", thresholdRuleCondition.Threshold)
d.Set("period", thresholdRuleCondition.WindowSize)
d.Set("aggregation", string(thresholdRuleCondition.TimeAggregation))

Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_monitor_metric_alertrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func resourceArmMonitorMetricAlertRuleRead(d *schema.ResourceData, meta interfac
if ruleCondition != nil {
if thresholdRuleCondition, ok := ruleCondition.AsThresholdRuleCondition(); ok && thresholdRuleCondition != nil {
d.Set("operator", string(thresholdRuleCondition.Operator))
d.Set("threshold", *thresholdRuleCondition.Threshold)
d.Set("threshold", thresholdRuleCondition.Threshold)
d.Set("period", thresholdRuleCondition.WindowSize)
d.Set("aggregation", string(thresholdRuleCondition.TimeAggregation))

Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
if ipProps := config.InterfaceIPConfigurationPropertiesFormat; ipProps != nil {
if v := ipProps.PrivateIPAddress; v != nil {
if i == 0 {
d.Set("private_ip_address", *v)
d.Set("private_ip_address", v)
}
addresses = append(addresses, *v)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ func resourceArmNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationR

d.Set("backend_address_pool_id", backendAddressPoolId)
d.Set("ip_configuration_name", ipConfigurationName)
if id := read.ID; id != nil {
d.Set("network_interface_id", *id)
}
d.Set("network_interface_id", read.ID)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationRead(d *schem

d.Set("application_security_group_id", applicationSecurityGroupId)
d.Set("ip_configuration_name", ipConfigurationName)
if id := read.ID; id != nil {
d.Set("network_interface_id", *id)
}
d.Set("network_interface_id", read.ID)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ func resourceArmNetworkInterfaceBackendAddressPoolAssociationRead(d *schema.Reso

d.Set("backend_address_pool_id", backendAddressPoolId)
d.Set("ip_configuration_name", ipConfigurationName)
if id := read.ID; id != nil {
d.Set("network_interface_id", *id)
}
d.Set("network_interface_id", read.ID)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ func resourceArmNetworkInterfaceNatRuleAssociationRead(d *schema.ResourceData, m

d.Set("ip_configuration_name", ipConfigurationName)
d.Set("nat_rule_id", natRuleId)
if id := read.ID; id != nil {
d.Set("network_interface_id", *id)
}
d.Set("network_interface_id", read.ID)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_relay_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func resourceArmRelayNamespaceRead(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error setting 'sku': %+v", err)
}

if err := d.Set("sku_name", *sku.Name); err != nil {
if err := d.Set("sku_name", sku.Name); err != nil {
return fmt.Errorf("Error setting 'sku_name': %+v", err)
}
} else {
Expand Down
24 changes: 0 additions & 24 deletions azurerm/resource_arm_resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func resourceArmResourceGroup() *schema.Resource {
Create: resourceArmResourceGroupCreateUpdate,
Read: resourceArmResourceGroupRead,
Update: resourceArmResourceGroupCreateUpdate,
Exists: resourceArmResourceGroupExists,
Delete: resourceArmResourceGroupDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand Down Expand Up @@ -105,29 +104,6 @@ func resourceArmResourceGroupRead(d *schema.ResourceData, meta interface{}) erro
return tags.FlattenAndSet(d, resp.Tags)
}

func resourceArmResourceGroupExists(d *schema.ResourceData, meta interface{}) (bool, error) {
client := meta.(*ArmClient).resource.GroupsClient
ctx := meta.(*ArmClient).StopContext

id, err := azure.ParseAzureResourceID(d.Id())
if err != nil {
return false, fmt.Errorf("Error parsing Azure Resource ID %q: %+v", d.Id(), err)
}

name := id.ResourceGroup

resp, err := client.Get(ctx, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return false, nil
}

return false, fmt.Errorf("Error reading resource group: %+v", err)
}

return true, nil
}

func resourceArmResourceGroupDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).resource.GroupsClient
ctx := meta.(*ArmClient).StopContext
Expand Down
Loading