From cbaef97de7eb4497ec097c93897dc494e192a188 Mon Sep 17 00:00:00 2001 From: Peter Hewitt Date: Sat, 16 Oct 2021 12:55:00 -0400 Subject: [PATCH] implement terraform import correctly --- provider/resource_immutable_tag_rule.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/provider/resource_immutable_tag_rule.go b/provider/resource_immutable_tag_rule.go index 3c7aea9..8b36645 100644 --- a/provider/resource_immutable_tag_rule.go +++ b/provider/resource_immutable_tag_rule.go @@ -99,6 +99,23 @@ func resourceImmutableTagRuleRead(d *schema.ResourceData, m interface{}) error { for _, rule := range immutableTagRuleModels { if rule.Id == tagId { log.Printf("[DEBUG] found tag id %d", tagId) + d.Set("disabled", rule.Disabled) + d.Set("project_id", strings.ReplaceAll(projectImmutableTagRulePath, models.PathImmutableTagRules, "")) + + switch rule.ImmutableTagRuleTagSelectors[0].Decoration { + case "matches": + d.Set("tag_matching", rule.ImmutableTagRuleTagSelectors[0].Pattern) + case "excludes": + d.Set("tag_excluding", rule.ImmutableTagRuleTagSelectors[0].Pattern) + } + + switch rule.ScopeSelectors.Repository[0].Decoration { + case "repoMatches": + d.Set("repo_matching", rule.ScopeSelectors.Repository[0].Pattern) + case "excludes": + d.Set("repo_excluding", rule.ScopeSelectors.Repository[0].Pattern) + } + return nil } }