@@ -2,6 +2,7 @@ package codestarconnections
2
2
3
3
import (
4
4
"fmt"
5
+ "log"
5
6
6
7
"github.com/aws/aws-sdk-go/aws"
7
8
"github.com/aws/aws-sdk-go/service/codestarconnections"
@@ -10,6 +11,7 @@ import (
10
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
11
12
"github.com/hashicorp/terraform-provider-aws/internal/conns"
12
13
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
14
+ "github.com/hashicorp/terraform-provider-aws/internal/tfresource"
13
15
"github.com/hashicorp/terraform-provider-aws/internal/verify"
14
16
"github.com/hashicorp/terraform-provider-aws/names"
15
17
)
@@ -20,6 +22,7 @@ func ResourceConnection() *schema.Resource {
20
22
Read : resourceConnectionRead ,
21
23
Update : resourceConnectionUpdate ,
22
24
Delete : resourceConnectionDelete ,
25
+
23
26
Importer : & schema.ResourceImporter {
24
27
State : schema .ImportStatePassthrough ,
25
28
},
@@ -29,35 +32,30 @@ func ResourceConnection() *schema.Resource {
29
32
Type : schema .TypeString ,
30
33
Computed : true ,
31
34
},
32
-
33
35
"connection_status" : {
34
36
Type : schema .TypeString ,
35
37
Computed : true ,
36
38
},
37
-
38
- "name" : {
39
- Type : schema .TypeString ,
40
- Required : true ,
41
- ForceNew : true ,
42
- },
43
-
44
39
"host_arn" : {
45
40
Type : schema .TypeString ,
46
41
Optional : true ,
47
42
ForceNew : true ,
48
- ConflictsWith : []string {"provider_type" },
49
43
ValidateFunc : verify .ValidARN ,
44
+ ConflictsWith : []string {"provider_type" },
45
+ },
46
+ "name" : {
47
+ Type : schema .TypeString ,
48
+ Required : true ,
49
+ ForceNew : true ,
50
50
},
51
-
52
51
"provider_type" : {
53
52
Type : schema .TypeString ,
54
53
Optional : true ,
55
54
ForceNew : true ,
56
55
Computed : true ,
57
- ConflictsWith : []string {"host_arn" },
58
56
ValidateFunc : validation .StringInSlice (codestarconnections .ProviderType_Values (), false ),
57
+ ConflictsWith : []string {"host_arn" },
59
58
},
60
-
61
59
"tags" : tftags .TagsSchema (),
62
60
"tags_all" : tftags .TagsSchemaComputed (),
63
61
},
@@ -71,28 +69,31 @@ func resourceConnectionCreate(d *schema.ResourceData, meta interface{}) error {
71
69
defaultTagsConfig := meta .(* conns.AWSClient ).DefaultTagsConfig
72
70
tags := defaultTagsConfig .MergeTags (tftags .New (d .Get ("tags" ).(map [string ]interface {})))
73
71
74
- params := & codestarconnections.CreateConnectionInput {
75
- ConnectionName : aws .String (d .Get ("name" ).(string )),
72
+ name := d .Get ("name" ).(string )
73
+ input := & codestarconnections.CreateConnectionInput {
74
+ ConnectionName : aws .String (name ),
76
75
}
77
76
78
- if v , ok := d .GetOk ("provider_type " ); ok {
79
- params . ProviderType = aws .String (v .(string ))
77
+ if v , ok := d .GetOk ("host_arn " ); ok {
78
+ input . HostArn = aws .String (v .(string ))
80
79
}
81
80
82
- if v , ok := d .GetOk ("host_arn " ); ok {
83
- params . HostArn = aws .String (v .(string ))
81
+ if v , ok := d .GetOk ("provider_type " ); ok {
82
+ input . ProviderType = aws .String (v .(string ))
84
83
}
85
84
86
85
if len (tags ) > 0 {
87
- params .Tags = Tags (tags .IgnoreAWS ())
86
+ input .Tags = Tags (tags .IgnoreAWS ())
88
87
}
89
88
90
- resp , err := conn .CreateConnection (params )
89
+ log .Printf ("[DEBUG] Creating CodeStar Connections Connection: %s" , input )
90
+ output , err := conn .CreateConnection (input )
91
+
91
92
if err != nil {
92
- return fmt .Errorf ("error creating CodeStar connection : %w" , err )
93
+ return fmt .Errorf ("creating CodeStar Connections Connection (%s) : %w" , name , err )
93
94
}
94
95
95
- d .SetId (aws .StringValue (resp .ConnectionArn ))
96
+ d .SetId (aws .StringValue (output .ConnectionArn ))
96
97
97
98
return resourceConnectionRead (d , meta )
98
99
}
@@ -102,8 +103,9 @@ func resourceConnectionRead(d *schema.ResourceData, meta interface{}) error {
102
103
defaultTagsConfig := meta .(* conns.AWSClient ).DefaultTagsConfig
103
104
ignoreTagsConfig := meta .(* conns.AWSClient ).IgnoreTagsConfig
104
105
105
- connection , err := findConnectionByARN (conn , d .Id ())
106
- if ! d .IsNewResource () && tfawserr .ErrCodeEquals (err , codestarconnections .ErrCodeResourceNotFoundException ) {
106
+ connection , err := FindConnectionByARN (conn , d .Id ())
107
+
108
+ if ! d .IsNewResource () && tfresource .NotFound (err ) {
107
109
names .LogNotFoundRemoveState (names .CodeStarConnections , names .ErrActionReading , ResConnection , d .Id ())
108
110
d .SetId ("" )
109
111
return nil
@@ -113,33 +115,29 @@ func resourceConnectionRead(d *schema.ResourceData, meta interface{}) error {
113
115
return names .Error (names .CodeStarConnections , names .ErrActionReading , ResConnection , d .Id (), err )
114
116
}
115
117
116
- if connection == nil {
117
- return fmt .Errorf ("error reading CodeStar connection (%s): empty response" , d .Id ())
118
- }
119
-
120
118
arn := aws .StringValue (connection .ConnectionArn )
121
119
d .SetId (arn )
122
120
d .Set ("arn" , connection .ConnectionArn )
123
121
d .Set ("connection_status" , connection .ConnectionStatus )
124
- d .Set ("name" , connection .ConnectionName )
125
122
d .Set ("host_arn" , connection .HostArn )
123
+ d .Set ("name" , connection .ConnectionName )
126
124
d .Set ("provider_type" , connection .ProviderType )
127
125
128
126
tags , err := ListTags (conn , arn )
129
127
130
128
if err != nil {
131
- return fmt .Errorf ("error listing tags for CodeStar Connection (%s): %w" , arn , err )
129
+ return fmt .Errorf ("listing tags for CodeStar Connections Connection (%s): %w" , arn , err )
132
130
}
133
131
134
132
tags = tags .IgnoreAWS ().IgnoreConfig (ignoreTagsConfig )
135
133
136
134
//lintignore:AWSR002
137
135
if err := d .Set ("tags" , tags .RemoveDefaultConfig (defaultTagsConfig ).Map ()); err != nil {
138
- return fmt .Errorf ("error setting tags: %w" , err )
136
+ return fmt .Errorf ("setting tags: %w" , err )
139
137
}
140
138
141
139
if err := d .Set ("tags_all" , tags .Map ()); err != nil {
142
- return fmt .Errorf ("error setting tags_all: %w" , err )
140
+ return fmt .Errorf ("setting tags_all: %w" , err )
143
141
}
144
142
145
143
return nil
@@ -152,7 +150,7 @@ func resourceConnectionUpdate(d *schema.ResourceData, meta interface{}) error {
152
150
o , n := d .GetChange ("tags_all" )
153
151
154
152
if err := UpdateTags (conn , d .Get ("arn" ).(string ), o , n ); err != nil {
155
- return fmt .Errorf ("error Codestar Connection (%s) tags: %w" , d .Id (), err )
153
+ return fmt .Errorf ("updating CodeStar Connections Connection (%s) tags: %w" , d .Id (), err )
156
154
}
157
155
}
158
156
@@ -162,14 +160,17 @@ func resourceConnectionUpdate(d *schema.ResourceData, meta interface{}) error {
162
160
func resourceConnectionDelete (d * schema.ResourceData , meta interface {}) error {
163
161
conn := meta .(* conns.AWSClient ).CodeStarConnectionsConn
164
162
163
+ log .Printf ("[DEBUG] Deleting CodeStar Connections Connection: %s" , d .Id ())
165
164
_ , err := conn .DeleteConnection (& codestarconnections.DeleteConnectionInput {
166
165
ConnectionArn : aws .String (d .Id ()),
167
166
})
167
+
168
168
if tfawserr .ErrCodeEquals (err , codestarconnections .ErrCodeResourceNotFoundException ) {
169
169
return nil
170
170
}
171
+
171
172
if err != nil {
172
- return fmt .Errorf ("error deleting CodeStar connection : %w" , err )
173
+ return fmt .Errorf ("deleting CodeStar Connections Connection (%s) : %w" , d . Id () , err )
173
174
}
174
175
175
176
return nil
0 commit comments