@@ -86,6 +86,10 @@ func resourceProject() *schema.Resource {
86
86
}
87
87
}
88
88
89
+ // type SmallProject struct {
90
+ // Links *bitbucket.ProjectLinks `json:"links,omitempty"`
91
+ // }
92
+
89
93
func newProjectFromResource (d * schema.ResourceData ) * bitbucket.Project {
90
94
project := & bitbucket.Project {
91
95
Name : d .Get ("name" ).(string ),
@@ -94,7 +98,7 @@ func newProjectFromResource(d *schema.ResourceData) *bitbucket.Project {
94
98
Key : d .Get ("key" ).(string ),
95
99
}
96
100
97
- if v , ok := d .GetOk ("link" ); ok && len (v .([]interface {})) > 0 && v .([]interface {}) != nil {
101
+ if v , ok := d .GetOk ("link" ); d . IsNewResource () && ok && len (v .([]interface {})) > 0 && v .([]interface {}) != nil {
98
102
project .Links = expandProjectLinks (v .([]interface {}))
99
103
}
100
104
@@ -103,6 +107,7 @@ func newProjectFromResource(d *schema.ResourceData) *bitbucket.Project {
103
107
104
108
func resourceProjectUpdate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
105
109
c := m .(Clients ).genClient
110
+ // client := m.(Clients).httpClient
106
111
projectApi := c .ApiClient .ProjectsApi
107
112
project := newProjectFromResource (d )
108
113
@@ -112,11 +117,41 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, m interf
112
117
projectKey = d .Get ("key" ).(string )
113
118
}
114
119
115
- _ , _ , err := projectApi .WorkspacesWorkspaceProjectsProjectKeyPut (c .AuthContext , * project , projectKey , d .Get ("owner" ).(string ))
120
+ log .Printf ("[DEBUG] Project Update Body: %#v" , project )
121
+ project .Links = nil
122
+
123
+ prj , _ , err := projectApi .WorkspacesWorkspaceProjectsProjectKeyPut (c .AuthContext , * project , projectKey , d .Get ("owner" ).(string ))
116
124
if err := handleClientError (err ); err != nil {
117
125
return diag .FromErr (err )
118
126
}
119
127
128
+ log .Printf ("[DEBUG] Project Update Res: %#v" , prj )
129
+
130
+ // if d.HasChange("link") {
131
+ // if v, ok := d.GetOk("link"); ok && len(v.([]interface{})) > 0 && v.([]interface{}) != nil {
132
+
133
+ // smallProject := SmallProject{
134
+ // Links: expandProjectLinks(v.([]interface{})),
135
+ // }
136
+
137
+ // payload, err := json.Marshal(smallProject)
138
+ // if err != nil {
139
+ // return diag.FromErr(err)
140
+ // }
141
+
142
+ // log.Printf("[DEBUG] Project Update Links Body: %s", string(payload))
143
+
144
+ // _, err = client.Put(fmt.Sprintf("2.0/workspaces/%s/projects/%s",
145
+ // d.Get("owner").(string), d.Get("key").(string),
146
+ // ), bytes.NewBuffer(payload))
147
+
148
+ // if err != nil {
149
+ // return diag.FromErr(err)
150
+ // }
151
+
152
+ // }
153
+ // }
154
+
120
155
return resourceProjectRead (ctx , d , m )
121
156
}
122
157
@@ -133,6 +168,8 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, m interf
133
168
134
169
owner := d .Get ("owner" ).(string )
135
170
171
+ log .Printf ("[DEBUG] Project Create Body: %#v" , project )
172
+
136
173
projRes , _ , err := projectApi .WorkspacesWorkspaceProjectsPost (c .AuthContext , * project , owner )
137
174
if err := handleClientError (err ); err != nil {
138
175
return diag .FromErr (err )
0 commit comments