Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Vang committed Mar 22, 2022
2 parents b403d95 + b356edd commit d4f6b15
Show file tree
Hide file tree
Showing 28 changed files with 58 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- `resource.scalr_role`: added new state migration (include `accounts:set-quotas` permission if needed) ([#116](https://github.com/Scalr/terraform-provider-scalr/pull/108))

### Fixed

- Correctly handle not found resources ([#117](https://github.com/Scalr/terraform-provider-scalr/pull/117))


## [1.0.0-rc27] - 2022-02-17

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -5,7 +5,7 @@ require (
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/scalr/go-scalr v0.0.0-20220210091404-3cda938612d1
github.com/scalr/go-scalr v0.0.0-20220312211514-108b023567c2
)

require (
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Expand Up @@ -299,8 +299,10 @@ github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6D
github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/scalr/go-scalr v0.0.0-20220210091404-3cda938612d1 h1:62zWA4iQ4iupEfjvF2jzwxokqcYUi9NM9HxTFXDD27A=
github.com/scalr/go-scalr v0.0.0-20220210091404-3cda938612d1/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220312161253-be1cf5060c4d h1:iqC/j9lCiqhlYJ/sR7HSDTtemAPXYWACw81cFMAn3OM=
github.com/scalr/go-scalr v0.0.0-20220312161253-be1cf5060c4d/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220312211514-108b023567c2 h1:jz7JFRKlVq+IOLZKginOXZrpn2N7/NvgrY5B29wIvig=
github.com/scalr/go-scalr v0.0.0-20220312211514-108b023567c2/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
Expand Down
4 changes: 2 additions & 2 deletions scalr/client_mock.go
Expand Up @@ -62,7 +62,7 @@ func (m *mockVariables) Read(ctx context.Context, varID string) (*scalr.Variable
v := m.ids[varID]

if v == nil {
return nil, scalr.ErrResourceNotFound{}
return nil, scalr.ErrResourceNotFound
}

return v, nil
Expand All @@ -71,7 +71,7 @@ func (m *mockVariables) Read(ctx context.Context, varID string) (*scalr.Variable
func (m *mockWorkspaces) Read(ctx context.Context, environment string, workspace string) (*scalr.Workspace, error) {
w := m.workspaceNames[workspaceNamesKey{environment, workspace}]
if w == nil {
return nil, scalr.ErrResourceNotFound{}
return nil, scalr.ErrResourceNotFound
}

return w, nil
Expand Down
4 changes: 2 additions & 2 deletions scalr/data_source_current_run.go
Expand Up @@ -113,7 +113,7 @@ func dataSourceScalrCurrentRunRead(d *schema.ResourceData, meta interface{}) err
log.Printf("[DEBUG] Read configuration of run: %s", runID)
run, err := scalrClient.Runs.Read(ctx, runID)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("Could not find run %s", runID)
}
return fmt.Errorf("Error retrieving run: %v", err)
Expand All @@ -122,7 +122,7 @@ func dataSourceScalrCurrentRunRead(d *schema.ResourceData, meta interface{}) err
log.Printf("[DEBUG] Read workspace of run: %s", runID)
workspace, err := scalrClient.Workspaces.ReadByID(ctx, run.Workspace.ID)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("Could not find workspace %s", run.Workspace.ID)
}
return fmt.Errorf("Error retrieving workspace: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion scalr/data_source_endpoint.go
Expand Up @@ -64,7 +64,7 @@ func dataSourceScalrEndpointRead(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Read endpoint with ID: %s", endpointID)
endpoint, err := scalrClient.Endpoints.Read(ctx, endpointID)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("Could not find endpoint %s: %v", endpointID, err)
}
return fmt.Errorf("Error retrieving endpoint: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions scalr/data_source_environment.go
Expand Up @@ -104,8 +104,8 @@ func dataSourceEnvironmentRead(d *schema.ResourceData, meta interface{}) error {
}

if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
return fmt.Errorf("Environment %s not found", envID)
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("Environment '%s' not found", envID)
}
return fmt.Errorf("Error retrieving environment: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion scalr/data_source_environment_test.go
Expand Up @@ -52,7 +52,7 @@ func TestAccEnvironmentDataSource_basic(t *testing.T) {
},
{
Config: testAccEnvironmentDataSourceNotFoundConfig(),
ExpectError: regexp.MustCompile("Environment with ID 'env-123' not found or user unauthorized"),
ExpectError: regexp.MustCompile("Environment 'env-123' not found"),
PlanOnly: true,
},
{
Expand Down
4 changes: 2 additions & 2 deletions scalr/data_source_module_version.go
Expand Up @@ -34,7 +34,7 @@ func dataSourceModuleVersionRead(d *schema.ResourceData, meta interface{}) error
source := d.Get("source").(string)
module, err := scalrClient.Modules.ReadBySource(ctx, source)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("Could not find module with source %s", source)
}
return fmt.Errorf("Error retrieving module: %v", err)
Expand All @@ -54,7 +54,7 @@ func dataSourceModuleVersionRead(d *schema.ResourceData, meta interface{}) error
}

if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("Could not find module with source %s and version %s", source, version)
}
return fmt.Errorf("Error retrieving module version: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions scalr/data_source_scalr_access_policy.go
Expand Up @@ -73,8 +73,8 @@ func dataSourceScalrAccessPolicyRead(d *schema.ResourceData, meta interface{}) e
ap, err := scalrClient.AccessPolicies.Read(ctx, id)

if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
return fmt.Errorf("AccessPolicy %s not found", id)
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("AccessPolicy '%s' not found", id)
}
return fmt.Errorf("Error reading configuration of access policy %s: %v", id, err)
}
Expand Down
2 changes: 1 addition & 1 deletion scalr/data_source_scalr_access_policy_test.go
Expand Up @@ -27,7 +27,7 @@ func TestAccScalrAccessPolicyDataSource_basic(t *testing.T) {
},
{
Config: testAccAccessPolicyDataSourceNotFoundConfig(),
ExpectError: regexp.MustCompile("IamAccessPolicy with ID 'ap-123' not found or user unauthorized"),
ExpectError: regexp.MustCompile("AccessPolicy 'ap-123' not found"),
PlanOnly: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion scalr/data_source_webhook.go
Expand Up @@ -70,7 +70,7 @@ func dataSourceScalrWebhookRead(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Read endpoint with ID: %s", webhookID)
webhook, err := scalrClient.Webhooks.Read(ctx, webhookID)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("Could not find webhook %s: %v", webhookID, err)
}
return fmt.Errorf("Error retrieving webhook: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion scalr/data_source_workspace.go
Expand Up @@ -145,7 +145,7 @@ func dataSourceScalrWorkspaceRead(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] Read configuration of workspace: %s", name)
workspace, err := scalrClient.Workspaces.Read(ctx, environmentID, name)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("Could not find workspace %s/%s", environmentID, name)
}
return fmt.Errorf("Error retrieving workspace: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_access_policy.go
Expand Up @@ -188,7 +188,7 @@ func resourceScalrAccessPolicyRead(d *schema.ResourceData, meta interface{}) err
ap, err := scalrClient.AccessPolicies.Read(ctx, id)

if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] AccessPolicy %s not found", id)
d.SetId("")
return nil
Expand Down Expand Up @@ -276,7 +276,7 @@ func resourceScalrAccessPolicyDelete(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Delete access policy %s", id)
err := scalrClient.AccessPolicies.Delete(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil
}
return fmt.Errorf(
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_agent_pool.go
Expand Up @@ -75,7 +75,7 @@ func resourceScalrAgentPoolRead(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Read configuration of agent pool: %s", id)
agentPool, err := scalrClient.AgentPools.Read(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] agent pool %s not found", id)
d.SetId("")
return nil
Expand Down Expand Up @@ -124,7 +124,7 @@ func resourceScalrAgentPoolDelete(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] Delete agent pool %s", id)
err := scalrClient.AgentPools.Delete(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil
}
return fmt.Errorf(
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_agent_pool_token.go
Expand Up @@ -78,7 +78,7 @@ func resourceScalrAgentPoolTokenRead(d *schema.ResourceData, meta interface{}) e
tokensList, err := scalrClient.AgentPoolTokens.List(ctx, poolID, options)

if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] agent pool %s not found", poolID)
d.SetId("")
return nil
Expand Down Expand Up @@ -138,7 +138,7 @@ func resourceScalrAgentPoolTokenDelete(d *schema.ResourceData, meta interface{})
log.Printf("[DEBUG] Delete agent pool token %s", id)
err := scalrClient.AccessTokens.Delete(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil
}
return fmt.Errorf(
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_endpoint.go
Expand Up @@ -116,7 +116,7 @@ func resourceScalrEndpointRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Read endpoint with ID: %s", endpointID)
endpoint, err := scalrClient.Endpoints.Read(ctx, endpointID)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
d.SetId("")
return nil
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func resourceScalrEndpointDelete(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Delete endpoint: %s", d.Id())
err := scalrClient.Endpoints.Delete(ctx, d.Id())
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil
}
return fmt.Errorf("Error deleting endpoint%s: %v", d.Id(), err)
Expand Down
7 changes: 3 additions & 4 deletions scalr/resource_scalr_environment.go
Expand Up @@ -3,10 +3,9 @@ package scalr
import (
"errors"
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
scalr "github.com/scalr/go-scalr"
"log"
)

func resourceScalrEnvironment() *schema.Resource {
Expand Down Expand Up @@ -145,7 +144,7 @@ func resourceScalrEnvironmentRead(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] Read configuration of environment: %s", environmentID)
environment, err := scalrClient.Environments.Read(ctx, environmentID)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
// If the resource isn't available, the function should set the ID
// to an empty string so Terraform "destroys" the resource in state.
d.SetId("")
Expand Down Expand Up @@ -225,7 +224,7 @@ func resourceScalrEnvironmentDelete(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] Delete environment %s", environmentID)
err := scalrClient.Environments.Delete(ctx, d.Id())
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil
}
return fmt.Errorf(
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_iam_team.go
Expand Up @@ -106,7 +106,7 @@ func resourceScalrIamTeamRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Read configuration of team %s", id)
t, err := scalrClient.Teams.Read(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] Team %s not found", id)
d.SetId("")
return nil
Expand Down Expand Up @@ -170,7 +170,7 @@ func resourceScalrIamTeamDelete(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Delete team %s", id)
err := scalrClient.Teams.Delete(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] Team %s not found", id)
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_module.go
Expand Up @@ -125,7 +125,7 @@ func resourceScalrModuleRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Read configuration of module: %s", id)
m, err := scalrClient.Modules.Read(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] Module %s no longer exists", id)
d.SetId("")
return nil
Expand Down Expand Up @@ -162,7 +162,7 @@ func resourceScalrModuleDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Delete module %s", id)
err := scalrClient.Modules.Delete(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil
}
return fmt.Errorf("Error deleting module %s: %v", id, err)
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_policy_group.go
Expand Up @@ -150,7 +150,7 @@ func resourceScalrPolicyGroupRead(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] Read configuration of policy group %s", id)
pg, err := scalrClient.PolicyGroups.Read(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] Policy group %s not found", id)
d.SetId("")
return nil
Expand Down Expand Up @@ -250,7 +250,7 @@ func resourceScalrPolicyGroupDelete(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] Delete policy group %s", id)
err := scalrClient.PolicyGroups.Delete(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] Policy group %s not found", id)
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions scalr/resource_scalr_policy_group_linkage.go
Expand Up @@ -41,7 +41,7 @@ func resourceScalrPolicyGroupLinkageImport(d *schema.ResourceData, meta interfac

policyGroup, environment, err := getLinkedResources(id, scalrClient)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil, fmt.Errorf("policy group linkage %s not found", id)
}
return nil, fmt.Errorf("error retrieving policy group linkage %s: %v", id, err)
Expand All @@ -62,7 +62,7 @@ func resourceScalrPolicyGroupLinkageCreate(d *schema.ResourceData, meta interfac

environment, err := scalrClient.Environments.Read(ctx, envID)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return fmt.Errorf("environment %s not found", envID)
}
return fmt.Errorf("error creating policy group linkage %s: %v", id, err)
Expand All @@ -88,7 +88,7 @@ func resourceScalrPolicyGroupLinkageRead(d *schema.ResourceData, meta interface{

policyGroup, environment, err := getLinkedResources(id, scalrClient)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] Policy group linkage %s not found", id)
d.SetId("")
return nil
Expand All @@ -109,7 +109,7 @@ func resourceScalrPolicyGroupLinkageDelete(d *schema.ResourceData, meta interfac

policyGroup, environment, err := getLinkedResources(id, scalrClient)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] Policy group linkage %s not found", id)
return nil
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func getLinkedResources(id string, scalrClient *scalr.Client) (
}
}
if policyGroup == nil {
return nil, nil, scalr.ErrResourceNotFound{}
return nil, nil, scalr.ErrResourceNotFound
}

return
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_role.go
Expand Up @@ -113,7 +113,7 @@ func resourceScalrRoleRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Read configuration of role: %s", id)
role, err := scalrClient.Roles.Read(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] Role %s not found", id)
d.SetId("")
return nil
Expand Down Expand Up @@ -179,7 +179,7 @@ func resourceScalrRoleDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Delete role %s", id)
err := scalrClient.Roles.Delete(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil
}
return fmt.Errorf(
Expand Down
4 changes: 2 additions & 2 deletions scalr/resource_scalr_run_triggers.go
Expand Up @@ -61,7 +61,7 @@ func resourceScalrRunTriggerDelete(d *schema.ResourceData, meta interface{}) err
err := scalrClient.RunTriggers.Delete(ctx, id)

if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
return nil
}
return fmt.Errorf("Error deleting run trigger %s: %v", id, err)
Expand All @@ -78,7 +78,7 @@ func resourceScalrRunTriggerRead(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Read run trigger %s", id)
runTrigger, err := scalrClient.RunTriggers.Read(ctx, id)
if err != nil {
if errors.Is(err, scalr.ErrResourceNotFound{}) {
if errors.Is(err, scalr.ErrResourceNotFound) {
log.Printf("[DEBUG] RunTrigger %s no longer exists", id)
d.SetId("")
return nil
Expand Down

0 comments on commit d4f6b15

Please sign in to comment.